黑客信息网:Arm(PWN学习笔记)

作者:紫东来
围观群众:35
更新于

黑客信息网:Arm(PWN学习笔记)
int __fastcall sub_17F80(char *a1)
{
  char *v1; // r4
  char *v2; // r0
  int v3; // r3
  char *v4; // r5
  unsigned int v5; // r9
  unsigned __int8 *v6; // r8
  char *v7; // r3
  int v8; // r6
  int v9; // t1
  int v10; // r10
  int v11; // r2
  int v12; // r2
  unsigned __int8 *v13; // r0
  bool v14; // zf
  int v15; // r2
  int v16; // t1
  bool v17; // zf
  char *v18; // ST14_4
  int v19; // r0
  int v20; // r2
  int v21; // r1
  ssize_t v22; // r5
  int v23; // r2
  char *v24; // r0
  const char *v25; // r6
  char *v26; // r0
  int result; // r0
  int v28; // r6
  FILE *v29; // r0
  int v30; // r6
  FILE *v31; // r0
  const char *v32; // r1
  int v33; // r2
  int v34; // r3
  char *v35; // r7
  char *v36; // r6
  char *v37; // r0
  int v38; // r7
  int v39; // r0
  int v40; // r2
  unsigned int v41; // r3
  char *haystack; // [sp+Ch] [bp-44h]
  char dest[4]; // [sp+18h] [bp-38h]
  int v44; // [sp+1Ch] [bp-34h]
  int v45; // [sp+20h] [bp-30h]
  int v46; // [sp+24h] [bp-2Ch]

  v1=a1;
  haystack=a1 + 13690;
  v2=strncpy(a1 + 21882, a1 + 13690, 0x1FFFu);
  v3=*((_DWORD *)v1 + 1629);
  v4=&v1[*((_DWORD *)v1 + 18) + 13690];
  v5=(unsigned int)&haystack[v3];
  if ( dword_34864 & 0x10 && (unsigned int)v4 < v5 )
  {
    haystack[v3]=0;
    sub_16534(v2);
    fprintf((FILE *)stderr, "%s:%d - Parsing headers ("%s")
", "src/read.c", 57, v4);
  }
  v6=(unsigned __int8 *)(v4 - 1);
  v7=v4;
  if ( (unsigned int)v4 >=v5 )
  {
LABEL_26:
    if ( *(_DWORD *)v1 > 3u )
      return 1;
    v21=*((_DWORD *)v1 + 1629);
    if ( (unsigned int)(0x1FFF - v21) >=0x2000 )
    {
      sub_1627C(v1);
      fwrite("No space left in client stream buffer, closing
", 1u, 0x2Fu, (FILE *)stderr);
      result=0;
      *((_DWORD *)v1 + 4)=400;
      *(_DWORD *)v1=12;
      return result;
    }
    v22=read(*((_DWORD *)v1 + 1112), &haystack[v21], 0x2000 - v21);
    if ( !strncmp(haystack, "POST", 4u) || (v26=(char *)strncmp(haystack, "PUT", 3u))==0 )
    {
      v23=(unsigned __int8)v1[13690];
      *(_DWORD *)dest=0;
      v44=0;
      v45=0;
      v46=0;
      if ( v23 )
      {
        v35=strstr(haystack, "Content-Length");
        v36=strchr(v35, '
');
        v37=strchr(v35, ':');
        strncpy(dest, v37 + 1, v36 - (v37 + 1)); // 这里复制有bug
      }
      v24=strstr(haystack, "\r
\r
");
      if ( v24 && (v25=v24 + 4, (signed int)(v24 + 4) <=(signed int)&haystack[*((_DWORD *)v1 + 1629) - 1 + v22]) )
      {
        v26=strstr(haystack, "upgrade.cgi");
        if ( !v26 || (v26=strstr(v25, "\r
\r
")) !=0 )
        {
          *((_DWORD *)v1 + 7623)=-1;
          goto LABEL_36;
        }
        v30=(int)(v1 + 28672);
        ++*((_DWORD *)v1 + 7623);
        v31=(FILE *)stderr;
        v32="req->iCount++(2)=%d
";
      }
      else
      {
        v30=(int)(v1 + 28672);
        v31=(FILE *)stderr;
        v32="req->iCount++=%d
";
        ++*((_DWORD *)v1 + 7623);
      }
      fprintf(v31, v32);
      v33=*(_DWORD *)(v30 + 1820);
      v26=(char *)(1717986919 * v33);
      *(_DWORD *)(v30 + 1820)=v33 % 20;
    }
LABEL_36:
    if ( v22 < 0 )
    {
      v34=*_errno_location();
      if ( v34 !=4 )
      {
        if ( v34==11 )
          return -1;
        sub_1627C(v1);
        perror("header read");
        *((_DWORD *)v1 + 4)=400;
        return 0;
      }
    }
    else
    {
      if ( !v22 )
      {
        if ( *((_DWORD *)v1 + 1628) >=(unsigned int)dword_37E6C || *((_DWORD *)v1 + 15) || *((_DWORD *)v1 + 1629) )
        {
          sub_1627C(v1);
          fwrite("client unexpectedly closed connection.
", 1u, 0x27u, (FILE *)stderr);
        }
        *((_DWORD *)v1 + 4)=400;
        return 0;
      }
      v14=(dword_34864 & 0x10)==0;
      *((_DWORD *)v1 + 1629) +=v22;
      if ( !v14 )
      {
        sub_16534(v26);
        v29=(FILE *)stderr;
        v1[*((_DWORD *)v1 + 1629) + 13690]=0;
        fprintf(v29, "%s:%d -- We read %d bytes: "%s"
", "src/read.c", 356, v22, "");
      }
    }
    return 1;
  }
  while ( 2 )
  {
    if ( *((_DWORD *)v1 + 7623) > 0 )
      goto LABEL_26;
    v9=(unsigned __int8)*v4++;
    v8=v9;
    v10=v9 - 13;
    if ( v9 !=13 )
      v10=1;
    if ( v8==161 )
      v11=v10 & 1;
    else
      v11=0;
    if ( v11 )
    {
      v12=*v6;
      v13=v6;
      v14=v12==0;
      if ( *v6 )
        v14=v12==10;
      if ( !v14 )
      {
        do
        {
          v16=*(v13-- - 1);
          v15=v16;
          v17=v16==0;
          if ( v16 )
            v17=v15==10;
        }
        while ( !v17 );
      }
      v18=v7;
      v19=strncmp((const char *)v13 + 1, "User-Agent:", 0xBu);
      v7=v18;
      if ( v19 )
      {
        sub_1627C(v1);
        fprintf((FILE *)stderr, "Illegal character (%d) in stream.
", 161);
        sub_1B8(v1);
        return 0;
      }
    }
    v20=*(_DWORD *)v1;
    switch ( *(_DWORD *)v1 )
    {
      case 0:
        if ( v8==13 )
        {
          *((_DWORD *)v1 + 17)=v7;
          *(_DWORD *)v1=1;
          goto LABEL_24;
        }
        if ( v8 !=10 )
          goto LABEL_24;
        *((_DWORD *)v1 + 17)=v7;
        *(_DWORD *)v1=2;
        goto LABEL_52;
      case 1:
        if ( v8 !=10 )
          goto LABEL_22;
        *(_DWORD *)v1=2;
LABEL_52:
        ++*((_DWORD *)v1 + 18);
        goto LABEL_53;
      case 2:
        if ( v8==13 )
        {
          *(_DWORD *)v1=3;
          goto LABEL_24;
        }
        if ( v8 !=10 )
        {
LABEL_23:
          *(_DWORD *)v1=0;
LABEL_24:
          ++*((_DWORD *)v1 + 18);
LABEL_25:
          ++v6;
          v7=v4;
          if ( (unsigned int)v4 >=v5 )
            goto LABEL_26;
          continue;
        }
LABEL_45:
        ++*((_DWORD *)v1 + 18);
        *(_DWORD *)v1=4;
LABEL_46:
        v28=sub_1A4F4(v1);
        if ( !v28 )
          return 0;
        if ( (unsigned int)(*((_DWORD *)v1 + 3) - 3) > 1 )
          return v28;
        v38=*((_DWORD *)v1 + 42);
        *((_DWORD *)v1 + 17)=&v1[*((_DWORD *)v1 + 1629) + 13690];
        *((_DWORD *)v1 + 16)=v4;
        *(_DWORD *)v1=5;
        if ( !v38 )
        {
          sub_1627C(v1);
          fwrite("Unknown Content-Length POST!
", 1u, 0x1Du, (FILE *)stderr);
          sub_1B8(v1);
          return 0;
        }
        v39=sub_216EC(v38);
        if ( v39 < 0 )
        {
          sub_1627C(v1);
          fprintf((FILE *)stderr, "Invalid Content-Length [%s] on POST!
", *((_DWORD *)v1 + 42));
          sub_1B8(v1);
          return 0;
        }
        v40=*((_DWORD *)v1 + 16);
        v41=*((_DWORD *)v1 + 17) - v40;
        *((_DWORD *)v1 + 11)=v39;
        *((_DWORD *)v1 + 12)=0;
        if ( v39 >=v41 )
          return v28;
        *((_DWORD *)v1 + 17)=v40 + v39;
        return v28;
      case 3:
        if ( v8==10 )
          goto LABEL_45;
LABEL_22:
        if ( v10 )
          goto LABEL_23;
        goto LABEL_24;
      default:
        ++*((_DWORD *)v1 + 18);
        if ( v20==2 )
        {
LABEL_53:
          **((_BYTE **)v1 + 17)=0;
          if ( *((_DWORD *)v1 + 17) - *((_DWORD *)v1 + 16) > 3071 )
          {
            sub_1627C(v1);
            fprintf(
              (FILE *)stderr,
              "Header too long at %lu bytes: "%s"
",
              *((_DWORD *)v1 + 17) - *((_DWORD *)v1 + 16));
            sub_1B8(v1);
            return 0;
          }
          if ( *((_DWORD *)v1 + 15) )
          {
            if ( !sub_1A878(v1) )
              return 0;
          }
          else
          {
            if ( !sub_19FF0(v1) )
              return 0;
            if ( *((_DWORD *)v1 + 2)==1 )
              return sub_1A4F4(v1);
          }
          *((_DWORD *)v1 + 16)=v4;
        }
        else if ( v20==4 )
        {
          goto LABEL_46;
        }
        goto LABEL_25;
    }
  }
}
黑客信息网:Arm(PWN学习笔记)

非特殊说明,本文版权归 茌平热点网 所有,转载请注明出处.

本文分类: 体育

本文标题: 黑客信息网:Arm(PWN学习笔记)

本文网址: http://cdslpx.com/tiyu/3255.html

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

网站分类
搜索
最新留言
    标签列表