EvilZone

Programming and Scripting => Scripting Languages => : d4rkcat January 15, 2014, 11:02:22 AM

: [Python] shellman.py - use a php webshell to get a bash like shell session
: d4rkcat January 15, 2014, 11:02:22 AM
Got bored yesterday so I made this bash-like webshell.

upload files with:
:
upload /path/to/local/file (remotefile)
download files with:
:
download remotefile (/path/to/local/file)
() == optional

You can use any of these local text editor software to write a file to the remote shell's pwd:
:
vi new.php
nano new.php
pico new.php
emacs new.php

Also there is tab completion for the contents of the remote directory.

Enjoy!

https://github.com/d4rkcat/shellman (https://github.com/d4rkcat/shellman)

[gist]d4rkcat/8433697[/gist]
: Re: [Python] shellman.py - use a php webshell to get a bash like shell session
: Phage January 15, 2014, 12:02:31 PM
Overall, nice idea/project :)


I have a few things to add though. I would recommend you to use Requests instead of urllib and urllib2. And at the bottom of your code, you have quite a log of if/else statements, try to find a way to shorten it down ;)
: Re: [Python] shellman.py - use a php webshell to get a bash like shell session
: kenjoe41 January 15, 2014, 06:11:31 PM
I have to agree i recently fell in love with Requests cos it's way superior to urllib/urllib2, quite pythonic and has a vast documentation, wait, it also supports asynchronous requests, oauth, etc. It always comes in handy in scraping projects where Beautifulsoup and lxml become alittle slow.
: Re: [Python] shellman.py - use a php webshell to get a bash like shell session
: vezzy January 15, 2014, 06:37:58 PM
Requests is superfluous and unnecessary for small scripts like this. The stdlib does fine.
: Re: [Python] shellman.py - use a php webshell to get a bash like shell session
: d4rkcat January 16, 2014, 05:27:57 AM
UPDATE:
 I have edited the script to only use post requests.

Thanks for the advice, Phage, kenjoe41 and vezzy.
Phage, I'm interested in cutting down on the if/else statements at the end of the script, but have been unable to do so without affecting the functionality. Any ideas are much appreciated! 
: Re: [Python] shellman.py - use a php webshell to get a bash like shell session
: RedBullAddicted January 16, 2014, 07:11:43 AM
Hi d4rkcat,

cutting down the if/else statements? Don't know what Phages solution would be but I would use Pythons awesome list, dictionary features :) Something like that:

: (Python)
>>> cmdreplace = {"ifconfig":"/sbin/ifconfig", "arp":"/usr/sbin/arp", "route":"/sbin/route"}
>>> for key, value in cmdreplace.iteritems():
...     print "take this %s and replace it with this %s" %(key, value)
...
take this arp and replace it with this /usr/sbin/arp
take this route and replace it with this /sbin/route
take this ifconfig and replace it with this /sbin/ifconfig

EDIT: I must admit I haven't had a closer look to your script before I wrote that. It seems like there are other things that could be optimized by implementing more functions. There are code-parts that are very similar. If I find the time today I will go through it more deeply and point these things out. Sadly I am very busy lately so I can't promise anything :P
: Re: [Python] shellman.py - use a php webshell to get a bash like shell session
: Phage January 16, 2014, 07:59:55 AM
Same solution as you bra ;)


I was in a bit of a hurry when I wrote that reply, so I didn't have the time to include code etc.
: Re: [Python] shellman.py - use a php webshell to get a bash like shell session
: d4rkcat January 16, 2014, 05:59:14 PM
Thanks for the ideas,

it doesnt work though...

: (python)
cmdreplace = {"ifconfig":"/sbin/ifconfig", "arp":"/usr/sbin/arp", "route":"/sbin/route"}
    for key, value in cmdreplace.iteritems():
        cmd = command.replace(key, value)

    print cmd

Only replaces the first command, ifconfig, same problem that I was having earlier..

UPDATE:
Have Included user agent password and script makes it own webshell with -g
: Re: [Python] shellman.py - use a php webshell to get a bash like shell session
: RedBullAddicted January 16, 2014, 06:31:25 PM
Yes.. you still need your conditional statement. Not exactly sure what it was but I guess something like that

: (Python)
cmdreplace = {"ifconfig":"/sbin/ifconfig", "arp":"/usr/sbin/arp", "route":"/sbin/route"}
for key, value in cmdreplace.iteritems():
    if key in command:
        cmd = command.replace(key, value)

Cheers,
RBA

: Re: [Python] shellman.py - use a php webshell to get a bash like shell session
: d4rkcat January 16, 2014, 06:44:40 PM
Yes.. you still need your conditional statement. Not exactly sure what it was but I guess something like that

Awesome!  Thanks RBA, that fixed it!

Python is pure pwnage. :D
: Re: [Python] shellman.py - use a php webshell to get a bash like shell session
: vezzy January 16, 2014, 07:12:32 PM
It's not Lisp, but it does the job.