metalx1000

netcat webserver notes

Mar 28th, 2017
1,037
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.59 KB | None | 0 0
  1. #webservers using netcat, busybox nc, or ncat
  2. #this will work with the full version of ncat, but busybox nc doesn't have '-c' builtin
  3. ncat -l -p 8000 -c 'echo -e "HTTP/1.1 200 OK\r\n$(date)\r\n\r\n";echo "<p>How are you today?</p>"'
  4.  
  5. #this is more universal
  6. { echo -e 'HTTP/1.1 200 OK\r\n'; echo "<p>How are you today?</p>"; } | netcat -l -p 8000
  7.  
  8. #keep it up and running after serving files
  9. while [ 1 ];do { echo -e 'HTTP/1.1 200 OK\r\n'; echo "<p>How are you today?</p>"; } | busybox -l -p 8000;done
  10.  
  11. #or you can pass it a file
  12. { echo -e 'HTTP/1.1 200 OK\r\n'; cat index.html; } | busybox nc -l -p 8000
  13.  
  14. #or the output of a command
  15. { echo -e 'HTTP/1.1 200 OK\r\n'; ls /; } |busybox nc -l -p 8000
  16.  
  17. #or a command with html tags
  18. #note the use of '<!DOCTYPE html>' and use single quotes due to special characters
  19. { echo -e 'HTTP/1.1 200 OK\r\n'; echo '<!DOCTYPE html>';echo "<ul>";for i in /*;do echo "<li>$i</li>";done;echo "</ul>"; } | busybox nc -l -p 8000
  20. { echo -e 'HTTP/1.1 200 OK\r\n'; echo '<!DOCTYPE html>';
  21. #you can embed images into your document with base64
  22. <img src='data:image/png;base64,[base64 code]'/>
  23. { echo -e 'HTTP/1.1 200 OK\r\n'; echo '<!DOCTYPE html>';cat img.html; } | busybox nc -l -p 8000
  24.  
  25. #display all png images in current folder
  26. { echo -e 'HTTP/1.1 200 OK\r\n'; echo '<!DOCTYPE html>';for i in *.png;do echo "<img src='data:image/png;base64,$(base64 $i)'/>";done; } | busybox nc -l -p 8000
  27.  
  28. { echo -e 'HTTP/1.1 200 OK\r\n'; echo '<!DOCTYPE html>';for i in *.ogg;do echo "<audio controls src='data:audio/ogg;base64,$(base64 $i)'></audio>";done; } | busybox nc -l -p 8000
Add Comment
Please, Sign In to add comment