Author Topic: [Python] shellman.py - use a php webshell to get a bash like shell session  (Read 1925 times)

0 Members and 1 Guest are viewing this topic.

Offline d4rkcat

  • Knight
  • **
  • Posts: 287
  • Cookies: 115
  • He who controls the past controls the future. He who controls the present controls the past.
    • View Profile
    • Scripts
Got bored yesterday so I made this bash-like webshell.

upload files with:
Code: [Select]
upload /path/to/local/file (remotefile)
download files with:
Code: [Select]
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:
Code: [Select]
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

[gist]d4rkcat/8433697[/gist]
« Last Edit: January 18, 2014, 05:57:15 am by d4rkcat »
Jabber (OTR required): thed4rkcat@einfachjabber.de    Email (PGP required): thed4rkcat@yandex.com    PGP Key: here and here     Blog

<sofldan> not asking for anyone to hold my hand uber space shuttle door gunner guy.


Offline Phage

  • VIP
  • Overlord
  • *
  • Posts: 1280
  • Cookies: 120
    • View Profile
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 ;)
"Ruby devs do, in fact, get all the girls. No girl wants a python, but EVERY girl wants rubies" - connection

"It always takes longer than you expect, even when you take into account Hofstadter’s Law."

Offline kenjoe41

  • Symphorophiliac Programmer
  • Administrator
  • Baron
  • *
  • Posts: 990
  • Cookies: 224
    • View Profile
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.
If you can't explain it to a 6 year old, you don't understand it yourself.
http://upload.alpha.evilzone.org/index.php?page=img&img=GwkGGneGR7Pl222zVGmNTjerkhkYNGtBuiYXkpyNv4ScOAWQu0-Y8[<NgGw/hsq]>EvbQrOrousk[/img]

Offline vezzy

  • Royal Highness
  • ****
  • Posts: 771
  • Cookies: 172
    • View Profile
Requests is superfluous and unnecessary for small scripts like this. The stdlib does fine.
Quote from: Dippy hippy
Just brushing though. I will be semi active mainly came to find a HQ botnet, like THOR or just any p2p botnet

Offline d4rkcat

  • Knight
  • **
  • Posts: 287
  • Cookies: 115
  • He who controls the past controls the future. He who controls the present controls the past.
    • View Profile
    • Scripts
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! 
Jabber (OTR required): thed4rkcat@einfachjabber.de    Email (PGP required): thed4rkcat@yandex.com    PGP Key: here and here     Blog

<sofldan> not asking for anyone to hold my hand uber space shuttle door gunner guy.


Offline RedBullAddicted

  • Moderator
  • Sir
  • *
  • Posts: 519
  • Cookies: 189
    • View Profile
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:

Code: (Python) [Select]
>>> 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
« Last Edit: January 16, 2014, 07:44:54 am by RedBullAddicted »
Deep into that darkness peering, long I stood there, wondering, fearing, doubting, dreaming dreams no mortal ever dared to dream before. - Edgar Allan Poe

Offline Phage

  • VIP
  • Overlord
  • *
  • Posts: 1280
  • Cookies: 120
    • View Profile
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.
« Last Edit: January 16, 2014, 08:00:31 am by Phage »
"Ruby devs do, in fact, get all the girls. No girl wants a python, but EVERY girl wants rubies" - connection

"It always takes longer than you expect, even when you take into account Hofstadter’s Law."

Offline d4rkcat

  • Knight
  • **
  • Posts: 287
  • Cookies: 115
  • He who controls the past controls the future. He who controls the present controls the past.
    • View Profile
    • Scripts
Thanks for the ideas,

it doesnt work though...

Code: (python) [Select]
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
« Last Edit: January 16, 2014, 06:00:12 pm by d4rkcat »
Jabber (OTR required): thed4rkcat@einfachjabber.de    Email (PGP required): thed4rkcat@yandex.com    PGP Key: here and here     Blog

<sofldan> not asking for anyone to hold my hand uber space shuttle door gunner guy.


Offline RedBullAddicted

  • Moderator
  • Sir
  • *
  • Posts: 519
  • Cookies: 189
    • View Profile
Yes.. you still need your conditional statement. Not exactly sure what it was but I guess something like that

Code: (Python) [Select]
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

Deep into that darkness peering, long I stood there, wondering, fearing, doubting, dreaming dreams no mortal ever dared to dream before. - Edgar Allan Poe

Offline d4rkcat

  • Knight
  • **
  • Posts: 287
  • Cookies: 115
  • He who controls the past controls the future. He who controls the present controls the past.
    • View Profile
    • Scripts
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
« Last Edit: January 17, 2014, 09:40:43 am by d4rkcat »
Jabber (OTR required): thed4rkcat@einfachjabber.de    Email (PGP required): thed4rkcat@yandex.com    PGP Key: here and here     Blog

<sofldan> not asking for anyone to hold my hand uber space shuttle door gunner guy.


Offline vezzy

  • Royal Highness
  • ****
  • Posts: 771
  • Cookies: 172
    • View Profile
Re: [Python] shellman.py - use a php webshell to get a bash like shell session
« Reply #10 on: January 16, 2014, 07:12:32 pm »
It's not Lisp, but it does the job.
Quote from: Dippy hippy
Just brushing though. I will be semi active mainly came to find a HQ botnet, like THOR or just any p2p botnet