def recvall(self, timeout=None, interactive=False): """recvall(timeout = None) reads all bytes available on the process stdout before timeout""" if not interactive: print(parse.mark('recv')) buf = self.read(0x100000, timeout, no_warning=True) if context.log_level == 'debug': # and not interactive: parse.hexdump(buf) if not interactive: print(parse.mark('recved')) return buf
def recvuntil(self, delim, timeout=None): """recvuntil(delim, timeout = None) reads bytes until the delim is present on the process stdout before timeout""" print(parse.mark('recv')) # self.timeout=1000 buf = '' # while delim not in buf: while (len(buf) < len(delim) or buf[-len(delim):] != delim): buf += self.recvn(1, timeout, local_call=True) if context.log_level == 'debug': print(parse.hexdump(buf)) print(parse.mark('recved')) return buf
def recv(self, n, timeout=None): """recv(n, timeout = None) tries to read n bytes on the process stdout before timeout""" print(parse.mark('recv')) buf = '' if var.ter is not None: # if var.ter.poll() is None: while (len(buf) != n): buf += self.read(n - len(buf), timeout) # else: # var.ter=None # buf=self.read(n, timeout) else: buf = self.read(n, timeout) if context.log_level == 'debug': parse.hexdump(buf) print(parse.mark('recved')) return buf
def write(self, buf, interactive=False): """write(buf) sends the buf to the process stdin""" self.check_exit(True) if self.stdhandles: # and not self.check_exit(True): # byzero add rs = self.stdin.write(buf) if not interactive: print(parse.mark('send')) if context.log_level == 'debug': print(parse.hexdump(buf)) if context.length is None or len(buf) < context.length: sys.stdout.write(buf) else: print( parse.color("[-]: str too long, not show sending", 'red')) print(parse.mark('sended')) return rs
def write(self, buf, interactive=False): """write(buf) sends the buf to the socket""" # if not self.check_closed(True): # try: # return self.sock.send(buf) # except socket.error: # self._closed = True # log.warning("EOFError: Socket {:s} closed".format(self)) rs = self.sock.send(buf) if not interactive: print(parse.mark('send')) if context.log_level == 'debug': print(parse.hexdump(buf)) if context.length is None or len(buf) < context.length: sys.stdout.write(buf) else: print(parse.color("[-]: str too long, not show sending", 'red')) print(parse.mark('sended')) return rs
def recvn(self, n, timeout=None, local_call=False): """recvn(n, timeout = None) reads exactly n bytes on the process stdout before timeout""" if not local_call: print(parse.mark('recv')) buf = '' if var.ter is not None: # if var.ter.poll() is None: while (len(buf) != n): # print("winpwn run to here") buf += self.read(n - len(buf), timeout) # else: # print("winpwn run to here1",var.ter.poll()) # var.ter=None # buf=self.read(n, timeout) else: buf = self.read(n, timeout) if len(buf) != n: raise (EOFError("Timeout {:s} ".format(self))) if not local_call and context.log_level == 'debug': print(parse.hexdump(buf)) if not local_call: print(parse.mark('recved')) return buf
def interactive(self, escape=False): print(parse.mark('interact')) """interactive(escape = None) allows to interact directly with the socket (escape to show binary content received)""" interact(self, escape)