Skip to content

Instantly share code, notes, and snippets.

@mondwan
Last active October 24, 2023 07:16
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mondwan/d8605fe5311ce13e9573 to your computer and use it in GitHub Desktop.
HTTP request with netcat or openssl

About

This is a document about how to test HTTP requests by running openssl or nc

example_post_req.txt

  • Edit payload, pathanme, ip etc

Openssl

If you are running simulator with HTTPS, you need openssl

    $> cat example_post_req.txt | \
        openssl s_client -cert cert.pem  -connect 192.168.0.21:9999

Netcat (nc)

If you are running simulator with HTTP, nc is good enough.

    $> cat example_post_req.txt | nc IP 80
POST /cli/core HTTP/1.1
Host: 192.168.0.22
Connection: keep-alive
Content-Length: 53
Accept: application/json, text/javascript, */*; q=0.01
Origin: https://192.168.0.22
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.71 Safari/537.36
Content-Type: application/json; charset=UTF-8
Referer: https://192.168.0.22/cgi-bin/luci/;stok=e1ef57b08cb916ea6d9711e3d8b09a5a/smartmoments/status/utility
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.8,zh-TW;q=0.6,zh;q=0.4
[{"command":"command_reboot","args":{"--json":true}}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment