简体   繁体   中英

Setting up SSL connection and sending GET information

Not 100% if this is the right section, but I think so since it's a question about how to program it.

After studying the course Computer Networking, I got some ideas of stuff I want to try. One of these things is automatically logging in to a webpage that is locally hosted on our 'router'.

So the site is local, let's say on 192.168.150.1 - clicking on a 'free login' link logs you in with a pseudo account, which we will call Alice (we have ip adres 192.168.150.74.. So if you'd click the link you'd send a GET request like:

192.168.0.1/login?dst=&username=T-Alice

Now I used wireshark to check the packet stream and it's encrypted - this is the packet stream:

No.     Time        Source                Destination           Protocol Info
      1 0.000000    192.168.150.74        192.168.150.1         TCP      50704 > https [SYN] Seq=0 Win=14600 Len=0 MSS=1460 SACK_PERM=1 TSV=37133 TSER=0 WS=7
      2 0.001304    192.168.150.1         192.168.150.74        TCP      https > 50704 [SYN, ACK] Seq=0 Ack=1 Win=5792 Len=0 MSS=1460 SACK_PERM=1 TSV=17344316 TSER=37133 WS=1
      3 0.001372    192.168.150.74        192.168.150.1         TCP      50704 > https [ACK] Seq=1 Ack=1 Win=14720 Len=0 TSV=37133 TSER=17344316
      4 0.001969    192.168.150.74        192.168.150.1         TLSv1    Client Hello
      5 0.003568    192.168.150.1         192.168.150.74        TCP      https > 50704 [ACK] Seq=1 Ack=406 Win=6864 Len=0 TSV=17344316 TSER=37133
      6 0.010537    192.168.150.1         192.168.150.74        TLSv1    Server Hello, Certificate, Server Hello Done
      7 0.010587    192.168.150.74        192.168.150.1         TCP      50704 > https [ACK] Seq=406 Ack=1132 Win=16896 Len=0 TSV=37134 TSER=17344316
      8 0.013352    192.168.150.74        192.168.150.1         TLSv1    Client Key Exchange, Change Cipher Spec, Encrypted Handshake Message
      9 0.051304    192.168.150.1         192.168.150.74        TCP      https > 50704 [ACK] Seq=1132 Ack=732 Win=7936 Len=0 TSV=17344321 TSER=37134
     10 0.269299    192.168.150.1         192.168.150.74        TLSv1    Change Cipher Spec, Encrypted Handshake Message
     11 0.270405    192.168.150.74        192.168.150.1         TLSv1    Application Data
     12 0.271888    192.168.150.1         192.168.150.74        TCP      https > 50704 [ACK] Seq=1191 Ack=1377 Win=9226 Len=0 TSV=17344343 TSER=37160
     13 0.288841    192.168.150.1         192.168.150.74        TLSv1    Application Data, Application Data
     14 0.328065    192.168.150.74        192.168.150.1         TCP      50704 > https [ACK] Seq=1377 Ack=2625 Win=19840 Len=0 TSV=37166 TSER=17344344

Now what I want to ask (and do..) is:

Is it possible to make a program (preferably in C or C++, but lang doesn't really matter prob, unless some of them have better libs..) that sets up this secure connection for me so I can set that GET information to the router and get logged in? Or is there an easier way in code to do this? Can I let the program 'visit' 192.168.150.1 and leave the packet creation and SSL to the kernel? (--> even though I thought SSL has to be handled by the application itself..)

Windows and unix solutions/guidance are both welcome.. I'd like to make this for both.

Sorry if this 'confusing', I tried to ask the question as clear as possible :p - so I'd just like a bit of help on sending the GET information to the router, as if I visited the page manually and clicked the link.

If you really want to handle the HTTP programming (sending the GET command and so on) yourself, perhaps for learning purposes, but have something take care of the SSL/TLS for you, you could use something like stunnel to that server, and use your own application to connect the the local end of the tunnel.

Generally, a better option would be to use an HTTP library that also supports SSL/TLS. Libcurl is a good example of this.

Of course it's possible, you simply need to implement the following sequence:

  1. Create an SSL connection to the HTTPS server
  2. Send the HTTP GET request
  3. Read the response from the server
  4. Parse the HTML content in the HTTP response

There's plenty examples of requesting a HTTP page from a server using openssl, I found this one by searching 'openssl https example' on Google. The real challenge in my opinion is parsing the HTML content which has already been discussed on stackoverflow .

I would recommend that you attempt this using Python before implementing it in C++, good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM