LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-12-2013, 08:07 AM   #1
hal8000b
Member
 
Registered: Mar 2001
Location: UK
Distribution: Mint, Arch, Debian7
Posts: 194

Rep: Reputation: 23
How do I use this Python script


I am using gFTP with bookmarks. I have several FTP sites, but there is one password in gFTP that I need to decrypt, I found the following site:

http://www.g-loaded.eu/2009/05/07/de...-using-python/


I copied the python code and saved it as gftp.py and made it executable with chmod 755:

Code:
def gftp_descrable_password(password):
    """gftp password descrambler
 
    This code has been released in the Public Domain by the original author.
 
    """
    if not password.startswith('$'):
        return password
    newpassword = []
    pwdparts = map(ord, password)
    for i in range(1, len(pwdparts), 2):
        if ((pwdparts[i] & 0xc3) != 0x41 or
            (pwdparts[i+1] & 0xc3) != 0x41):
            return password
        newpassword.append(chr(((pwdparts[i] & 0x3c) << 2) +
                               ((pwdparts[i+1] & 0x3c) >> 2)))
    return "".join(newpassword)

However I do not know how to use the script. If I go to ~/.gFTP bookmarks and copy and paste the password I get a python error:


./gftp.py $hgugujhvjhvvhgv
./gftp.py: line 1: syntax error near unexpected token `('
./gftp.py: line 1: `def gftp_descrable_password(password):'


If I start script with python at a terminal e.g.

python gftp.py $njknjkbjhvjhvbjhv

There is no error but no password is displayed.
The password texts are random characters not a saved password.
Thanks in advance for help on this.

Last edited by hal8000b; 03-13-2013 at 05:51 PM.
 
Old 03-13-2013, 03:21 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
I don't know if there is any special relevance to gFTP here, but for a python script itself, you'd need to escape, or quote, the $ sign. Bash will interpret that string as the name of a variable in the current environment, not a literal string that happens to start with a dollar sign. go....

./script \$blah

or

./script '$blah'

also you'll not be able to run it directly without having a #!/usr/bin/python at the start as in your first example it's having to just run it as a shell script as it doesn't know it's python without that shebang at the start.[COLOR="Silver"]
python without that shebang at the start.

Last edited by acid_kewpie; 03-13-2013 at 03:23 AM.
 
Old 03-13-2013, 04:19 AM   #3
pgpython
Member
 
Registered: Dec 2005
Location: Sheffield, UK
Distribution: Gentoo
Posts: 142

Rep: Reputation: 32
In terms of making the script do something. all you have is a function which is never called. The usual way for a script to do something when it is run is:

Code:
if __name__ == "__main__":
   #Do some stuff when the script is run
This ensures that if your script is imported that the stuff will not get run. you can access command line arguments through the list sys.argv (remeber to import the sys module first!).
 
Old 03-13-2013, 04:37 AM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
Quote:
Originally Posted by pgpython View Post
In terms of making the script do something. all you have is a function which is never called. The usual way for a script to do something when it is run is:

Code:
if __name__ == "__main__":
   #Do some stuff when the script is run
This ensures that if your script is imported that the stuff will not get run. you can access command line arguments through the list sys.argv (remeber to import the sys module first!).
oh dear, i didn't even see that. Embarrassing!
 
Old 03-13-2013, 05:55 PM   #5
hal8000b
Member
 
Registered: Mar 2001
Location: UK
Distribution: Mint, Arch, Debian7
Posts: 194

Original Poster
Rep: Reputation: 23
Thanks for the quick replies. Although I didn't manage to get my python script working
I then tried wireshark and captured the ftp stream whilst using gFTP. The resulting
capture contained my password in plain ascii text. Marking as solved.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Python TypeError when calling Python program from a Bash script noppeli Programming 2 01-15-2013 08:06 AM
How to close open ports using a python script or a shell script in python ?? apanimesh061 Programming 3 11-20-2011 12:31 AM
Python related: How to access a Perl script behind a firewall from Python? vxc69 Programming 8 12-14-2010 07:32 AM
mysterious discrepancy b/w script results at terminal and in python script cedardoc Linux - Newbie 1 08-03-2010 03:59 PM
python cgi script and premature end of script headers Neruocomp Programming 1 07-28-2005 11:43 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration