Advertisement
metalx1000

Busybox file upload cgi script

Jul 23rd, 2017
776
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.82 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # POST upload format:
  4. # -----------------------------29995809218093749221856446032^M
  5. # Content-Disposition: form-data; name="file1"; filename="..."^M
  6. # Content-Type: application/octet-stream^M
  7. # ^M    <--------- headers end with empty line
  8. # file contents
  9. # file contents
  10. # file contents
  11. # ^M    <--------- extra empty line
  12. # -----------------------------29995809218093749221856446032--^M
  13.  
  14. folder=../uploads/
  15.  
  16. CR=`printf '\r'`
  17.  
  18. # CGI output must start with at least empty line (or headers)
  19. echo "Content-type: text/html"
  20. printf '\r\n'
  21.  
  22. while read -r line; do
  23.   #get file name of uploaded file
  24.   echo "$line" | grep "filename" > /dev/null && file="$(echo "$line"|cut -d\" -f4)"
  25.   test x"$line" = x"" && break
  26.   test x"$line" = x"$CR" && break
  27. done
  28.  
  29. echo "$file uploaded."
  30. cat >"${folder}${file}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement