pwn.sh(想不想做题更愉快点来着?

每次遇到题目的步骤:

  1. 下载文件和libc
  2. 新建文件夹并把它们复制进去
  3. 去上次做的题目那里复制一下脚本
  4. 改脚本中的文件名,libc名
  5. 去赛题网页复制服务器ip和port
  6. 删去上次的主体内容
  7. 开始做题

这也太麻烦了吧。于是乎,我自己写了一个能在一定程度上加快我开始做题速度的脚本(脚本的内容都是根据welpwn写的,welpwn在替换libc上太方便了。

上脚本

if [ $# -eq 0 ]; then
    echo "Usage:"
    echo "pwn.sh [filename] ([ip]) ([port]) ([libcname])"
    exit
elif [ $# -gt 0 ]; then
    chmod +x $1
    filename="pwn"$1".py"
    touch $filename
    echo "from PwnContext import *
from libnum import *

try:
    from IPython import embed as ipy
except ImportError:
    print ('IPython not installed.')

if __name__ == '__main__':        
    # context.terminal = ['tmux', 'splitw', '-h'] # uncomment this if you use tmux
    context.log_level = 'debug'
    # functions for quick script
    s       = lambda data               :ctx.send(str(data))        #in case that data is an int
    sa      = lambda delim,data         :ctx.sendafter(str(delim), str(data)) 
    sl      = lambda data               :ctx.sendline(str(data)) 
    sla     = lambda delim,data         :ctx.sendlineafter(str(delim), str(data)) 
    r       = lambda numb=4096          :ctx.recv(numb)
    ru      = lambda delims, drop=True  :ctx.recvuntil(delims, drop)
    irt     = lambda                    :ctx.interactive()
    rs      = lambda *args, **kwargs    :ctx.start(*args, **kwargs)
    dbg     = lambda gs='', **kwargs    :ctx.debug(gdbscript=gs, **kwargs)
    # misc functions
    uu32    = lambda data   :u32(data.ljust(4, '
if [ $# -eq 0 ]; then
echo "Usage:"
echo "pwn.sh [filename] ([ip]) ([port]) ([libcname])"
exit
elif [ $# -gt 0 ]; then
chmod +x $1
filename="pwn"$1".py"
touch $filename
echo "from PwnContext import *
from libnum import *
try:
from IPython import embed as ipy
except ImportError:
print ('IPython not installed.')
if __name__ == '__main__':        
# context.terminal = ['tmux', 'splitw', '-h'] # uncomment this if you use tmux
context.log_level = 'debug'
# functions for quick script
s       = lambda data               :ctx.send(str(data))        #in case that data is an int
sa      = lambda delim,data         :ctx.sendafter(str(delim), str(data)) 
sl      = lambda data               :ctx.sendline(str(data)) 
sla     = lambda delim,data         :ctx.sendlineafter(str(delim), str(data)) 
r       = lambda numb=4096          :ctx.recv(numb)
ru      = lambda delims, drop=True  :ctx.recvuntil(delims, drop)
irt     = lambda                    :ctx.interactive()
rs      = lambda *args, **kwargs    :ctx.start(*args, **kwargs)
dbg     = lambda gs='', **kwargs    :ctx.debug(gdbscript=gs, **kwargs)
# misc functions
uu32    = lambda data   :u32(data.ljust(4, '\0'))
uu64    = lambda data   :u64(data.ljust(8, '\0'))
" > $filename
echo "    ctx.binary = './"$1"'" >> $filename
if [ $# -gt 2 ]; then
echo "    ctx.remote = ('"$2"'," $3")" >> $filename
else
echo "    ctx.remote = ('0.0.0.0', 9999)"  >> $filename
fi
if [ $# -eq 4 ]; then
if [ "$4" != "libc.so.6" ]; then
mv $4 libc.so.6
fi
echo "    ctx.remote_libc = './libc.so.6'
ctx.debug_remote_libc = True"  >> $filename
fi
echo "    rs()
# rs('remote')
print(ctx.libc.path)" >> $filename
echo ""  >> $filename
echo ""  >> $filename
echo "    irt()" >> $filename
fi
echo "[*] created $filename successfully!"
code $filename --user-data-dir
')) uu64 = lambda data :u64(data.ljust(8, '
if [ $# -eq 0 ]; then
echo "Usage:"
echo "pwn.sh [filename] ([ip]) ([port]) ([libcname])"
exit
elif [ $# -gt 0 ]; then
chmod +x $1
filename="pwn"$1".py"
touch $filename
echo "from PwnContext import *
from libnum import *
try:
from IPython import embed as ipy
except ImportError:
print ('IPython not installed.')
if __name__ == '__main__':        
# context.terminal = ['tmux', 'splitw', '-h'] # uncomment this if you use tmux
context.log_level = 'debug'
# functions for quick script
s       = lambda data               :ctx.send(str(data))        #in case that data is an int
sa      = lambda delim,data         :ctx.sendafter(str(delim), str(data)) 
sl      = lambda data               :ctx.sendline(str(data)) 
sla     = lambda delim,data         :ctx.sendlineafter(str(delim), str(data)) 
r       = lambda numb=4096          :ctx.recv(numb)
ru      = lambda delims, drop=True  :ctx.recvuntil(delims, drop)
irt     = lambda                    :ctx.interactive()
rs      = lambda *args, **kwargs    :ctx.start(*args, **kwargs)
dbg     = lambda gs='', **kwargs    :ctx.debug(gdbscript=gs, **kwargs)
# misc functions
uu32    = lambda data   :u32(data.ljust(4, '\0'))
uu64    = lambda data   :u64(data.ljust(8, '\0'))
" > $filename
echo "    ctx.binary = './"$1"'" >> $filename
if [ $# -gt 2 ]; then
echo "    ctx.remote = ('"$2"'," $3")" >> $filename
else
echo "    ctx.remote = ('0.0.0.0', 9999)"  >> $filename
fi
if [ $# -eq 4 ]; then
if [ "$4" != "libc.so.6" ]; then
mv $4 libc.so.6
fi
echo "    ctx.remote_libc = './libc.so.6'
ctx.debug_remote_libc = True"  >> $filename
fi
echo "    rs()
# rs('remote')
print(ctx.libc.path)" >> $filename
echo ""  >> $filename
echo ""  >> $filename
echo "    irt()" >> $filename
fi
echo "[*] created $filename successfully!"
code $filename --user-data-dir
')) " > $filename echo " ctx.binary = './"$1"'" >> $filename if [ $# -gt 2 ]; then echo " ctx.remote = ('"$2"'," $3")" >> $filename else echo " ctx.remote = ('0.0.0.0', 9999)" >> $filename fi if [ $# -eq 4 ]; then if [ "$4" != "libc.so.6" ]; then mv $4 libc.so.6 fi echo " ctx.remote_libc = './libc.so.6' ctx.debug_remote_libc = True" >> $filename fi echo " rs() # rs('remote') print(ctx.libc.path)" >> $filename echo "" >> $filename echo "" >> $filename echo " irt()" >> $filename fi echo "[*] created $filename successfully!" code $filename --user-data-dir

可以去github上看一下,虽然是一个非常简单的脚本 https://github.com/DanisJiang/PwnScripts

它所做的:

  • 把文件改为可执行
  • 把脚本该有的内容填充
  • 加上文件的名字
  • 加上赛题的服务器ip和port
  • 更改libc的名字为libc.so.6,并填充到脚本里
  • 帮你在vs code 中打开

就像这样(得把它放在PATH里,这样就可以在那里都能用啦

初始的pwn脚本长这样:

from PwnContext import *
from libnum import *

try:
    from IPython import embed as ipy
except ImportError:
    print ('IPython not installed.')

if __name__ == '__main__':        
    # context.terminal = ['tmux', 'splitw', '-h'] # uncomment this if you use tmux
    context.log_level = 'debug'
    # functions for quick script
    s       = lambda data               :ctx.send(str(data))        #in case that data is an int
    sa      = lambda delim,data         :ctx.sendafter(str(delim), str(data)) 
    sl      = lambda data               :ctx.sendline(str(data)) 
    sla     = lambda delim,data         :ctx.sendlineafter(str(delim), str(data)) 
    r       = lambda numb=4096          :ctx.recv(numb)
    ru      = lambda delims, drop=True  :ctx.recvuntil(delims, drop)
    irt     = lambda                    :ctx.interactive()
    rs      = lambda *args, **kwargs    :ctx.start(*args, **kwargs)
    dbg     = lambda gs='', **kwargs    :ctx.debug(gdbscript=gs, **kwargs)
    # misc functions
    uu32    = lambda data   :u32(data.ljust(4, '
from PwnContext import *
from libnum import *
try:
from IPython import embed as ipy
except ImportError:
print ('IPython not installed.')
if __name__ == '__main__':        
# context.terminal = ['tmux', 'splitw', '-h'] # uncomment this if you use tmux
context.log_level = 'debug'
# functions for quick script
s       = lambda data               :ctx.send(str(data))        #in case that data is an int
sa      = lambda delim,data         :ctx.sendafter(str(delim), str(data)) 
sl      = lambda data               :ctx.sendline(str(data)) 
sla     = lambda delim,data         :ctx.sendlineafter(str(delim), str(data)) 
r       = lambda numb=4096          :ctx.recv(numb)
ru      = lambda delims, drop=True  :ctx.recvuntil(delims, drop)
irt     = lambda                    :ctx.interactive()
rs      = lambda *args, **kwargs    :ctx.start(*args, **kwargs)
dbg     = lambda gs='', **kwargs    :ctx.debug(gdbscript=gs, **kwargs)
# misc functions
uu32    = lambda data   :u32(data.ljust(4, '\0'))
uu64    = lambda data   :u64(data.ljust(8, '\0'))
ctx.binary = './hacknote'
ctx.remote = ('chall.pwnable.tw', 10102)
ctx.remote_libc = './libc.so.6'
ctx.debug_remote_libc = True
rs()
# rs('remote')
print(ctx.libc.path)
irt()
')) uu64 = lambda data :u64(data.ljust(8, '
from PwnContext import *
from libnum import *
try:
from IPython import embed as ipy
except ImportError:
print ('IPython not installed.')
if __name__ == '__main__':        
# context.terminal = ['tmux', 'splitw', '-h'] # uncomment this if you use tmux
context.log_level = 'debug'
# functions for quick script
s       = lambda data               :ctx.send(str(data))        #in case that data is an int
sa      = lambda delim,data         :ctx.sendafter(str(delim), str(data)) 
sl      = lambda data               :ctx.sendline(str(data)) 
sla     = lambda delim,data         :ctx.sendlineafter(str(delim), str(data)) 
r       = lambda numb=4096          :ctx.recv(numb)
ru      = lambda delims, drop=True  :ctx.recvuntil(delims, drop)
irt     = lambda                    :ctx.interactive()
rs      = lambda *args, **kwargs    :ctx.start(*args, **kwargs)
dbg     = lambda gs='', **kwargs    :ctx.debug(gdbscript=gs, **kwargs)
# misc functions
uu32    = lambda data   :u32(data.ljust(4, '\0'))
uu64    = lambda data   :u64(data.ljust(8, '\0'))
ctx.binary = './hacknote'
ctx.remote = ('chall.pwnable.tw', 10102)
ctx.remote_libc = './libc.so.6'
ctx.debug_remote_libc = True
rs()
# rs('remote')
print(ctx.libc.path)
irt()
')) ctx.binary = './hacknote' ctx.remote = ('chall.pwnable.tw', 10102) ctx.remote_libc = './libc.so.6' ctx.debug_remote_libc = True rs() # rs('remote') print(ctx.libc.path) irt()

附:

虽然是一个很简单的脚本但我觉得在很大程度上改善了我刚开始做题时候的心情,立马就可以上手,整个人愉快了好多哈哈哈

以后会尝试着加入更多的东西,比如帮你先checksec啥的。反正我希望一行命令让我做更多的事hhh

说点什么

avatar

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据

  Subscribe  
提醒