ElfCrackMe1

*:first-child {
margin-top: 0 !important;
}

body>*:last-child {
margin-bottom: 0 !important;
}

/* BLOCKS
=============================================================================*/

p, blockquote, ul, ol, dl, table, pre {
margin: 15px 0;
}

/* HEADERS
=============================================================================*/

h1, h2, h3, h4, h5, h6 {
margin: 20px 0 10px;
padding: 0;
font-weight: bold;
-webkit-font-smoothing: antialiased;
}

h1 tt, h1 code, h2 tt, h2 code, h3 tt, h3 code, h4 tt, h4 code, h5 tt, h5 code, h6 tt, h6 code {
font-size: inherit;
}

h1 {
font-size: 28px;
color: #000;
}

h2 {
font-size: 24px;
border-bottom: 1px solid #ccc;
color: #000;
}

h3 {
font-size: 18px;
}

h4 {
font-size: 16px;
}

h5 {
font-size: 14px;
}

h6 {
color: #777;
font-size: 14px;
}

body>h2:first-child, body>h1:first-child, body>h1:first-child+h2, body>h3:first-child, body>h4:first-child, body>h5:first-child, body>h6:first-child {
margin-top: 0;
padding-top: 0;
}

a:first-child h1, a:first-child h2, a:first-child h3, a:first-child h4, a:first-child h5, a:first-child h6 {
margin-top: 0;
padding-top: 0;
}

h1+p, h2+p, h3+p, h4+p, h5+p, h6+p {
margin-top: 10px;
}

/* LINKS
=============================================================================*/

a {
color: #4183C4;
text-decoration: none;
}

a:hover {
text-decoration: underline;
}

/* LISTS
=============================================================================*/

ul, ol {
padding-left: 30px;
}

ul li > :first-child,
ol li > :first-child,
ul li ul:first-of-type,
ol li ol:first-of-type,
ul li ol:first-of-type,
ol li ul:first-of-type {
margin-top: 0px;
}

ul ul, ul ol, ol ol, ol ul {
margin-bottom: 0;
}

dl {
padding: 0;
}

dl dt {
font-size: 14px;
font-weight: bold;
font-style: italic;
padding: 0;
margin: 15px 0 5px;
}

dl dt:first-child {
padding: 0;
}

dl dt>:first-child {
margin-top: 0px;
}

dl dt>:last-child {
margin-bottom: 0px;
}

dl dd {
margin: 0 0 15px;
padding: 0 15px;
}

dl dd>:first-child {
margin-top: 0px;
}

dl dd>:last-child {
margin-bottom: 0px;
}

/* CODE
=============================================================================*/

pre, code, tt {
font-size: 12px;
font-family: Consolas, "Liberation Mono", Courier, monospace;
}

code, tt {
margin: 0 0px;
padding: 0px 0px;
white-space: nowrap;
border: 1px solid #eaeaea;
background-color: #f8f8f8;
border-radius: 3px;
}

pre>code {
margin: 0;
padding: 0;
white-space: pre;
border: none;
background: transparent;
}

pre {
background-color: #f8f8f8;
border: 1px solid #ccc;
font-size: 13px;
line-height: 19px;
overflow: auto;
padding: 6px 10px;
border-radius: 3px;
}

pre code, pre tt {
background-color: transparent;
border: none;
}

kbd {
-moz-border-bottom-colors: none;
-moz-border-left-colors: none;
-moz-border-right-colors: none;
-moz-border-top-colors: none;
background-color: #DDDDDD;
background-image: linear-gradient(#F1F1F1, #DDDDDD);
background-repeat: repeat-x;
border-color: #DDDDDD #CCCCCC #CCCCCC #DDDDDD;
border-image: none;
border-radius: 2px 2px 2px 2px;
border-style: solid;
border-width: 1px;
font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
line-height: 10px;
padding: 1px 4px;
}

/* QUOTES
=============================================================================*/

blockquote {
border-left: 4px solid #DDD;
padding: 0 15px;
color: #777;
}

blockquote>:first-child {
margin-top: 0px;
}

blockquote>:last-child {
margin-bottom: 0px;
}

/* HORIZONTAL RULES
=============================================================================*/

hr {
clear: both;
margin: 15px 0;
height: 0px;
overflow: hidden;
border: none;
background: transparent;
border-bottom: 4px solid #ddd;
padding: 0;
}

/* TABLES
=============================================================================*/

table th {
font-weight: bold;
}

table th, table td {
border: 1px solid #ccc;
padding: 6px 13px;
}

table tr {
border-top: 1px solid #ccc;
background-color: #fff;
}

table tr:nth-child(2n) {
background-color: #f8f8f8;
}

/* IMAGES
=============================================================================*/

img {
max-width: 100%
}
-->

简单的Elf逆向Writeup

题目来源:IDF实验室 CTF训练营;题目链接http://ctf.idf.cn/index.php?g=game&m=article&a=index&id=39
题目下载:http://pan.baidu.com/s/1kTl5wxD

解法1:

IDA查看伪代码法:

  1. 下载文件,现在Linux环境下运行,可以看到关键字符串u r wrongplz enter the flag:
  2. 把文件拖到IDA中,shift+F12查找字符串,双击u r right跳转到相应位置
  3. 如下图,双击调用关键字符串u r right的函数,
    跳转后F5查看伪代码如下
     int __cdecl main(int argc, const char **argv, const char **envp)
    {
    int v3; // ebx@6
    const char **v4; // rdx@22
    __int64 v6; // [sp+0h] [bp-C0h]@1
    __int64 v7; // [sp+8h] [bp-B8h]@1
    __int64 v8; // [sp+10h] [bp-B0h]@1
    __int64 v9; // [sp+18h] [bp-A8h]@1
    __int64 v10; // [sp+20h] [bp-A0h]@1
    __int64 v11; // [sp+28h] [bp-98h]@1
    __int64 v12; // [sp+30h] [bp-90h]@1
    __int64 v13; // [sp+38h] [bp-88h]@1
    int v14; // [sp+40h] [bp-80h]@1
    char v15[]; // [sp+80h] [bp-40h]@2
    char v16; // [sp+91h] [bp-2Fh]@14
    char v17; // [sp+92h] [bp-2Eh]@15
    char v18; // [sp+93h] [bp-2Dh]@16
    char v19; // [sp+94h] [bp-2Ch]@17
    char v20; // [sp+95h] [bp-2Bh]@18
    int v21; // [sp+A4h] [bp-1Ch]@1
    int v22; // [sp+A8h] [bp-18h]@7
    int i; // [sp+ACh] [bp-14h]@9 v21 = ;
    memset(&v6, , 0x58uLL);
    v6 = 854698492143LL;
    v7 = 880468295913LL;
    v8 = 597000454391LL;
    v9 = 605590388953LL;
    v10 = 932007903423LL;
    v11 = 760209211613LL;
    v12 = 579820585151LL;
    v13 = 940597838039LL;
    v14 = ;
    printf(
    "plz enter the flag:",
    argv,
    11LL,
    854698492143LL,
    880468295913LL,
    597000454391LL,
    605590388953LL,
    932007903423LL,
    760209211613LL,
    579820585151LL,
    940597838039LL,
    *(_QWORD *)&v14);
    while ( )
    {
    v3 = v21;
    v15[v3] = getch();
    if ( !v15[v3] || v15[v21] == )
    break;
    if ( v15[v21] == )
    {
    printf("\b\b", v6, v7, v8, v9, v10, v11, v12, v13, *(_QWORD *)&v14);
    --v21;
    }
    else
    {
    putchar(v15[v21++]);
    }
    }
    v22 = ;
    if ( v21 != )
    v22 = ;
    for ( i = ; i <= ; ++i )
    {
    if ( v15[i] != (*((_DWORD *)&v6 + i) - ) / )
    {
    v22 = ;
    argv = (const char **)((*((_DWORD *)&v6 + i) - ) / );
    printf("%d", argv, v6, v7, v8, v9, v10, v11, v12, v13, *(_QWORD *)&v14);
    }
    }
    if ( v16 != || v17 != || v18 != || v19 != || v20 != )
    v22 = ;
    v15[v21] = ;
    puts("\r");
    if ( v22 )
    {
    puts("u r wrong\r\n\r");
    main((unsigned __int64)"u r wrong\r\n\r", argv, v4);
    }
    else
    {
    puts("u r right!\r");
    }
    return ;
    }

分析这段伪代码,可以得到关键部分如下:

  • v22需为0,按'/'随手注释
  • 如上图中所示,要使v22==0,所有v22=1的语句均不能运行,则需要:v21==22,69行判断均不进入,既要 v15[i] != (*((_DWORD *)&v6 + i) - 1) / 2,同时,v16~v20依次等于48,56,50,51,125,即字符0823}(在相应数字上按r键把相应的ASCII码转换为字符)
    同样按'/'键随手注释
  • 找到定义v15的代码处,则根据上述的关键条件,初步猜测需要输入22位字符,其中前17位存入字符串v15中,后5位覆盖v16~v20的取值,使v16~v20分别等于0823}
  • 继续向下分析,找到输入的代码块,经过分析可得到关键信息如上图,其中v21即为输入的长度,通过关键条件v21==22验证了猜测输入字符串长度为22,同时需要保证输入的后五位为0823}
  • 向下分析v15需要满足的条件,着重分析v15[i] != (*((_DWORD *)&v6 + i) - 1) / 2

    &v6为取v6的地址;(_DWORD *)&v6强制转化为_DWORD型指针,即两个字节;((_DWORD *)&v6 + i)为从&v6向后取sizeof(_DWORD)*i个字节;*((_DWORD *)&v6 + i) - 1)为取从&v6向后取4i个字节的值
    关于地址与指针加减问题http://www.cnblogs.com/WangAoBo/p/6365114.html

  • 如上,分析v6的赋值段代码,v6~v13为_int64型,占8个字节,int型为4个字节,化为16进制如上图
  • v6~v14通过小端存储方式在内存中的存储情况如上

则可写出python脚本解得flag: wctf{ElF_lnX_Ckm_0823}


python脚本如下:

 v6=[0x0EF, 0x0C7, 0x0E9, 0x0CD, 0x0F7, 0x8B, 0x0D9,
0x8D, 0x0BF, 0x0D9, 0x0DD, 0x0B1, 0x0BF, 0x87,
0x0D7, 0x0DB, 0x0BF] L=[]
for i in range(17):
num = (v6[i] - 1)/2
ans = chr(int(num))
L.append(ans) flag = ''.join(L)
flag+='0823}' print(flag)

IDF-CTF-简单的Elf逆向Writeup的更多相关文章

  1. IDF实验室-简单的ELF逆向 writeup

    题目:http://ctf.idf.cn/index.php?g=game&m=article&a=index&id=39 下载得到ElfCrackMe1文件,直接用IDA打开 ...

  2. 简单的Elf逆向Writeup

    ElfCrackMe1 html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acrony ...

  3. IDF实验室-简单编程-字符统计 writeup

    题目地址:http://ctf.idf.cn/index.php?g=game&m=article&a=index&id=37 网站:http://ctf.idf.cn/gam ...

  4. IDF实验室-简单编程-特殊的日子 writeup

    题目:http://ctf.idf.cn/index.php?g=game&m=article&a=index&id=50 题目提示要爆破,代表加密应该是不可逆的. 密文:4D ...

  5. IDF - CTF - 牛刀小试

    找学校CTF好地方,IDF实验室CTF训练营(http://ctf.idf.cn/). . 刚接触CTF.来玩下牛刀小试.AK了. . 好爽好爽.. 1.摩斯password 嘀嗒嘀嗒嘀嗒嘀嗒 时针它 ...

  6. elf逆向入门

    一: 在linux下进行调试时容易出现权限不够的情况:此时解决办法就是chmod 777+文件名提升权限,以实验吧debug为例,给出了简单的32elf文件,我在查看一些资料以后发现,我需要在main ...

  7. CTF的一道安卓逆向

    前几天打CTF时遇到的一道安卓逆向,这里简单的写一下思路 首先用jadx打开apk文件,找到simplecheck处(文件名是simplecheck),可以看到基本逻辑就是通过函数a对输入的内容进行判 ...

  8. 一种简单的ELF加固方法

    介绍一种ELF文件函数粒度的加固方法,可以有效防止对程序的静态分析.这是一种有源码加固方式,需要被加固程序中代码配合.加固流程如下: 1)读取ELF文件头,获取e_phoff和e_phnum2)通过E ...

  9. CTF 湖湘杯 2018 WriteUp (部分)

    湖湘杯 2018 WriteUp (部分),欢迎转载,转载请注明出处! 1.  CodeCheck(WEB) 测试admin ‘ or ‘1’=’1’# ,php报错.点击登录框下面的滚动通知,URL ...

随机推荐

  1. idea修改忽视文件产生得bug

    为了提交代码方便,在idea中增加了忽视文件选项. 这一修改可把自己坑惨了,更改代码运行代码得时候,连打印都没出来,对照了半天代码 也没发现是哪里得错误,后来想到某次修改代码后class文件并没改变, ...

  2. 164.扩展User模型-继承AbstractUser

    继承自AbstractUser: 如果Abstractuser中定义的字段不能够满足你的项目的要求,并且不想要修改原来User对象上的一些字段,只是想要增加一些字段,那么这时候可以直接继承自djang ...

  3. 棋盘划分问题中4的k次方减一是三的倍数

    1.数学归纳法(万物皆可数学归纳) ①当n=1时:4-1=3(是三的倍数) ②假设n-1成立证明n成立:4n-1=4n-1*(4-1)+4n-1-1 =3*4n-1+(4n-1-1) 所以4n-1%3 ...

  4. js json -> <-object

    1.利用原生JSON对象,将对象转为字符串 var jsObj = {}; jsObj.testArray = [1,2,3,4,5]; jsObj.name = 'CSS3'; jsObj.date ...

  5. React的组件化

    所谓组件,即封装起来的具有独立功能的UI部件.React推荐以组件的方式去重新思考UI构成,将UI上每一个功能相对独立的模块定义成组件,然后将小的组件通过组合或者嵌套的方式构成大的组件,最终完成整体U ...

  6. linux异常 - unzip: 未找到命令

    问题描述 unzip: Command Not Found 或 zip: Command Not Found 或unzip: 未找到命令 解决方法 如果是Ubuntu的的系统可以用下面的命令安装:su ...

  7. Python - 反向遍历序列(列表、字符串、元组等)的五种方式

    1. reversed() a = [1, 2, 3, 4] for i in reversed(a): print(i) 2. range(len(a)-1, -1, -1) a = [1, 2, ...

  8. ts中接口的用法

    ts中的接口主要的作用是: 对“对象”进行约束描述 对“类”的一部分行为进行抽象 一.属性接口 接口中可定义 确定属性.可选属性.任意属性.只读属性 1.确定属性 interface UserInfo ...

  9. 解决Creating Server TCP listening socket 54.179.160.162:7001: bind: Cannot assign requested address

    背景:之前在测试环境搭过一个redis集群,运维把服务器重启之后我重新开启redis集群始终起不来,但是有没有任何日志,经过如下步骤最终解决问题 1.修改日志路径,根据日志查看为什么会启动失败[前期操 ...

  10. StringBuilder与String的区别

    String 在进行运算时(如赋值.拼接等)会产生一个新的实例,而 StringBuilder 则不会.所以在大量字符串拼接或频繁对某一字符串进行操作时最好使用 StringBuilder,不要使用  ...