Skip to content

Instantly share code, notes, and snippets.

@Jinmo
Created May 10, 2020 07:28
Show Gist options
  • Save Jinmo/f367a665148a6f1af79d9071886058ef to your computer and use it in GitHub Desktop.
Save Jinmo/f367a665148a6f1af79d9071886058ef to your computer and use it in GitHub Desktop.
pwntools windows; at least remote() works
diff --git "a/pwnlib/context/__init__.py" "b/pwnlib/context/__init__.py"
index 6d43994..e813de6 100644
--- "a/pwnlib/context/__init__.py"
+++ "b/pwnlib/context/__init__.py"
@@ -26,6 +26,8 @@ import socks
from pwnlib.config import register_config
from pwnlib.device import Device
from pwnlib.timeout import Timeout
+import colorama
+colorama.init()
__all__ = ['context', 'ContextType', 'Thread']
diff --git "a/pwnlib/term/term.py" "b/pwnlib/term/term.py"
index d86c9bd..8e8268d 100644
--- "a/pwnlib/term/term.py"
+++ "b/pwnlib/term/term.py"
@@ -2,14 +2,14 @@ from __future__ import absolute_import
from __future__ import division
import atexit
-import fcntl
+# import fcntl
import os
import re
import signal
import six
import struct
import sys
-import termios
+# import termios
import threading
import traceback
@@ -43,7 +43,7 @@ def hide_cursor():
def update_geometry():
global width, height
- hw = fcntl.ioctl(fd.fileno(), termios.TIOCGWINSZ, '1234')
+ # hw = fcntl.ioctl(fd.fileno(), termios.TIOCGWINSZ, '1234')
h, w = struct.unpack('hh', hw)
# if the window shrunk and theres still free space at the bottom move
# everything down
@@ -74,9 +74,9 @@ def setupterm():
update_geometry()
hide_cursor()
do('smkx') # keypad mode
- if not settings:
- settings = termios.tcgetattr(fd.fileno())
- mode = termios.tcgetattr(fd.fileno())
+ # if not settings:
+ # settings = termios.tcgetattr(fd.fileno())
+ # mode = termios.tcgetattr(fd.fileno())
IFLAG = 0
OFLAG = 1
CFLAG = 2
@@ -84,14 +84,14 @@ def setupterm():
ISPEED = 4
OSPEED = 5
CC = 6
- mode[LFLAG] = mode[LFLAG] & ~(termios.ECHO | termios.ICANON | termios.IEXTEN)
- mode[CC][termios.VMIN] = 1
- mode[CC][termios.VTIME] = 0
- termios.tcsetattr(fd, termios.TCSAFLUSH, mode)
+ # mode[LFLAG] = mode[LFLAG] & ~(termios.ECHO | termios.ICANON | termios.IEXTEN)
+ # mode[CC][termios.VMIN] = 1
+ # mode[CC][termios.VTIME] = 0
+ # termios.tcsetattr(fd, termios.TCSAFLUSH, mode)
def resetterm():
- if settings:
- termios.tcsetattr(fd.fileno(), termios.TCSADRAIN, settings)
+ # if settings:
+ # termios.tcsetattr(fd.fileno(), termios.TCSADRAIN, settings)
show_cursor()
do('rmkx')
fd.write(' \x08') # XXX: i don't know why this is needed...
diff --git "a/pwnlib/term/termcap.py" "b/pwnlib/term/termcap.py"
index adef420..d94b33e 100644
--- "a/pwnlib/term/termcap.py"
+++ "b/pwnlib/term/termcap.py"
@@ -8,9 +8,29 @@ import sys
cache = None
+def windows_get(cap, *args, **kwargs):
+ if cap == 'setaf':
+ return '\x1b[3%dm' % args[0]
+
+ known = {
+ 'rev': 7,
+ 'bold': 1,
+ 'smul': 4
+ }
+
+ val = known.get(cap)
+
+ if val is not None:
+ return '\x1b[%dm' % val
+
+ return ''
+
def get(cap, *args, **kwargs):
default = kwargs.pop('default', '')
+ if os.name == 'nt':
+ return windows_get(cap, *args, **kwargs)
+
if 'PWNLIB_NOTERM' in os.environ:
return ''
diff --git "a/pwnlib/tubes/process.py" "b/pwnlib/tubes/process.py"
index 4ac16d4..5927fd0 100644
--- "a/pwnlib/tubes/process.py"
+++ "b/pwnlib/tubes/process.py"
@@ -4,19 +4,20 @@ from __future__ import division
import ctypes
import errno
-import fcntl
+# import fcntl
import logging
import os
import platform
-import pty
-import resource
+# import pty
+pty=None
+# import resource
import select
import signal
import six
import stat
import subprocess
import time
-import tty
+# import tty
from pwnlib import qemu
from pwnlib.context import context
@@ -345,8 +346,8 @@ class process(tube):
# return as soon as a the first byte is available
if self.proc.stdout:
fd = self.proc.stdout.fileno()
- fl = fcntl.fcntl(fd, fcntl.F_GETFL)
- fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)
+ # fl = fcntl.fcntl(fd, fcntl.F_GETFL)
+ # fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)
# Save off information about whether the binary is setuid / setgid
self.uid = os.getuid()
@@ -376,13 +377,14 @@ class process(tube):
ADDR_NO_RANDOMIZE = 0x0040000
ctypes.CDLL('libc.so.6').personality(ADDR_NO_RANDOMIZE)
- resource.setrlimit(resource.RLIMIT_STACK, (-1, -1))
+ # resource.setrlimit(resource.RLIMIT_STACK, (-1, -1))
except Exception:
self.exception("Could not disable ASLR")
# Assume that the user would prefer to have core dumps.
try:
- resource.setrlimit(resource.RLIMIT_CORE, (-1, -1))
+ pass
+ # resource.setrlimit(resource.RLIMIT_CORE, (-1, -1))
except Exception:
pass
diff --git "a/pwnlib/tubes/ssh.py" "b/pwnlib/tubes/ssh.py"
index 25c0169..2ff8201 100644
--- "a/pwnlib/tubes/ssh.py"
+++ "b/pwnlib/tubes/ssh.py"
@@ -30,7 +30,7 @@ from pwnlib.util.sh_string import sh_string
# Kill the warning line:
# No handlers could be found for logger "paramiko.transport"
paramiko_log = logging.getLogger("paramiko.transport")
-h = logging.StreamHandler(open('/dev/null','w+'))
+h = logging.NullHandler()
h.setFormatter(logging.Formatter())
paramiko_log.addHandler(h)
diff --git "a/pwnlib/ui.py" "b/pwnlib/ui.py"
index 0450765..46d829e 100644
--- "a/pwnlib/ui.py"
+++ "b/pwnlib/ui.py"
@@ -1,7 +1,7 @@
from __future__ import absolute_import
from __future__ import division
-import fcntl
+# import fcntl
import os
import signal
import six
@@ -9,7 +9,7 @@ import string
import struct
import subprocess
import sys
-import termios
+# import termios
import time
import types
@@ -41,7 +41,7 @@ atexception.register(lambda:os.kill(os.getppid(), signal.SIGUSR1))
p.recvuntil(b"\33[6n")
except EOFError:
raise EOFError("process terminated with code: %r (%r)" % (p.poll(True), p.stderr.read()))
- fcntl.ioctl(p.stdout.fileno(), termios.TIOCSWINSZ, struct.pack("hh", 80, 80))
+ # fcntl.ioctl(p.stdout.fileno(), termios.TIOCSWINSZ, struct.pack("hh", 80, 80))
p.stdout.write(b"\x1b[1;1R")
return p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment