Send a syn packet through http proxy in python 3
<p>I'm able to send a tcp syn packet through a socks, but what about HTTP proxies? Is it possible?</p>

<p>This is the code with sock (it works):</p>

<pre><code>p = bytes(IP(dst="DESTINATIONIP")/TCP(flags="S", sport=RandShort(), dport=80))
        while True:
            try:
                socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, socksip, sockport, True)
                s = socks.socksocket()
                s.connect((DESTINATIONIP,DESTINATIONPORT))
                s.send(p)
                print ("Request Sent!")
            except:
                print ("An error occurred.")
</code></pre>

<p>I presume when you say "send a SYN packet" you mean "make a connection", since you can't send any bare IP-level packets via SOCKS, only make connections and send TCP / UDP payload.</p>

<p>For http proxy, it's similar, you just use the http tunneling command "CONNECT", e.g. you send</p>

<pre><code>CONNECT somewhere.example.com:443 HTTP/1.1
Host: somewhere.example.com
etc
</code></pre>

<p>and wait for a </p>

<pre><code>HTTP/1.1 200 Connection established
etc
</code></pre>

<p>response.  You will need to account for all the data in the http response message (up until you receive the end of the HTTP headers) so you don't mix that up with payload.</p>

python sockets python-3.x scapy http-proxy