KISS πŸ‡ΊπŸ‡¦

Stop the war!

Stop the war in Ukraine! Fuck putin!

More information is at: https://war.ukraine.ua/.

There is a fund to support the Ukrainian Army: https://savelife.in.ua/en/donate/, and there is a special bank account that accepts funds in multiple currencies: https://bank.gov.ua/en/about/support-the-armed-forces. I donated to them. Please donate if you can!

Killer putin

Killer putin. Source: politico.eu.

Arrested putin

"It hasn't happened yet, but it will happen sooner or later. Beautiful photo, isn't it?" Source: twitter.

Sending HTTP POST request with netcat

| comments

I have a D-Link Wi-Fi router that sometimes loses the PPPoE connection and thus requires reconnect. The standard way is to go to the web interface, login, and press the button. But it’s a long way, especially on an android device. Wouldn’t it be much nicer and faster to simply run a script?

I’ve installed busybox with the Busybox installer, and gotten wget, although very limited, it can’t send POST requests. curl is not there. So we’ll have to do with netcat. Here’s how to login:

1
2
3
BODY="html_response_page=login_fail.asp&login_name=login&login_pass=pass&graph_id=${GRAPH_ID}&login_n=login&log_pass=pass&graph_code=&login=Login"
BODY_LEN=$( busybox echo -n ${BODY} | wc -c )
busybox echo -ne "POST /login.cgi HTTP/1.0\r\nHost: 199.188.1.99\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: ${BODY_LEN}\r\n\r\n${BODY}" | nc -i 3 199.188.1.99 80

Here, $BODY contains the form data which is sent in the POST body. We then calculate its length, because it’s required from the Content-Length HTTP header, as well as the Content-Type header. That’s what echo generates and sends to the socket:

1
2
3
4
5
6
POST /login.cgi HTTP/1.0
Host: 199.188.1.99
Content-Type: application/x-www-form-urlencoded
Content-Length: 134

html_response_page=login_fail.asp&login_name=login&login_pass=pass&graph_id=abcdef&login_n=login&log_pass=pass&graph_code=&login=Login

The -i 3 parameter to nc is important because otherwise it doesn’t wait for a response. All in all, nothing special in this script, but gives an example how to send a POST with netcat. BTW, this may not be so easy with HTTP 2.0 if it’s going to be binary.

For the sake of completeness, you can find the scripts to restart the PPPoE connection for OS X, Linux, and Android below:

OS X (rpppoe_osx.sh) download
1
2
3
4
5
#!/bin/bash

GRAPH_ID=$( curl 'http://199.188.1.99/login_auth.asp' --http1.0 | sed -nEe '/id="graph_id"/{s/.*value="([^"]+)".*/\1/;p;}' )
curl 'http://199.188.1.99/login.cgi' --http1.0 -H 'Host: 199.188.1.99' --data "html_response_page=login_fail.asp&login_name=login&login_pass=pass&graph_id=${GRAPH_ID}&login_n=login&log_pass=pass&graph_code=&login=Login"
curl --http1.0 -X POST http://199.188.1.99/pppoe_00_disconnect.cgi
Linux (rpppoe_linux.sh) download
1
2
3
4
5
6
#!/bin/bash

URL="http://199.188.1.99/"
GRAPH_ID=$( wget "${URL}login_auth.asp" -O- | sed -nE '/id="graph_id"/{s/.*value="([^"]+)".*/\1/;p;}' )
wget "${URL}login.cgi" --header='Host: 199.188.1.99' --post-data="html_response_page=login_fail.asp&login_name=login&login_pass=pass&graph_id=${GRAPH_ID}&login_n=login&log_pass=pass&graph_code=&login=Login" -O-
wget "${URL}pppoe_00_disconnect.cgi" --post-data='' -O-
Android (rpppoe_android.sh) download
1
2
3
4
5
6
7
#!/system/bin/sh
URL="http://199.188.1.99/"
GRAPH_ID=$( wget "${URL}login_auth.asp" -O- | sed -nE '/id="graph_id"/{s/.*value="([^"]+)".*/\1/; p;}' )
BODY="html_response_page=login_fail.asp&login_name=login&login_pass=pass&graph_id=${GRAPH_ID}&login_n=login&log_pass=pass&graph_code=&login=Login"
BODY_LEN=$( busybox echo -n ${BODY} | wc -c )
busybox echo -ne "POST /login.cgi HTTP/1.0\r\nHost: 199.188.1.99\r\nContent-Type:application/x-www-form-urlencoded\r\nContent-Length: ${BODY_LEN}\r\n\r\n${BODY}" | nc -i 3 199.188.1.99 80
wget "${URL}pppoe_00_disconnect.cgi" -O-

android, bash, linux, terminal

Note: The comments in the blog are provided by disqus.com; if you don't see the comment form under the post, probably your browser or its extension (such as uBlock Origin or NoScript) blocks their scripts.

« Neurobics Xcode and AppleScript »

Comments