Miscellaneous Network Hacks
Random Collection Of Network Hacks I Picked Up
Private network file-sharing with python simple server
Share files between hosts on the same private network with python SimpleHTTPServer
. On the host with the files, run iconfig
and grep for en0
to find its private ip on the network.
Now run the python simple http server in the directory with the files we want to share.
Now any other device on the private network can access these files by visiting 192.168.128.117:8000
.
Because the hosts are on the same private network, downloads should be much faster than email attachments or Dropbox.
See running network processes with `lsof`
lsof
is a *nix command-line tool that shows the list of opened files and the processes that opened them. These opened files include disk files but also network sockets. Using the -i
flag will show opened files that correspond with internet addresses, ie.
You can also use netstat
to get the same information more or less.
See live network traffic with `tcpdump`
tcpdump
will show live tcp traffic packets. It’s the command-line version to wireshark.
You can specify specific ports too via tcpdump -A 'port 80'
Inspect raw server HTTP responses with `telnet`
telnet
is an ancient tool (1969) for logging into a remote host. It’s the precursor to ssh
. We can use it now to make requests to web servers and view raw http responses, among other things.
Sending and listening for TCP and UDP connections with `nc`
netcat
or nc
is a utility for sending and listening to TCP/UDP connections. We can use nc
to see raw HTTP requests and responses.
Hackers can also use nc
to scan for ports. nmap
is another port-scanning tool.
Testing APIs With Curl
You’re building an API but the client hasn’t been developed yet. You can still use curl
to sanity-check your API.
A GET
request with authorization headers using the -H
flag. The -v
flag stands for verbose, since why not.
curl -v \
-H "Accept: application/json" \
-H "Cookie: remember_user_token=MxaQFJIiIkMmEkMTAkU1czUVVaMlN" \
-H "App-Client-Id: Whitelisted-App-123" \
localhost:13000/api/teemo/shrooms
A POST
request. Note the -d
stands for data, which automatically makes this a POST
request .
curl \
-d "name=Teemo&weapon=shrooms" \
localhost:13000/api/champions
However, we can be explicit that it’s a POST
request by using the -X
flag, which can also be used to specify HEAD
PUT
DELETE
requests. Here is a POST
request with a JSON payload.
curl \
-H "Content-Type: application/json" \
-X POST \
-d '{"name":"Teemo", "weapon":"shrooms"}' \
localhost:13000/api/champions
We’re basically using the command-line version of Postman, except more L33T.