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. 基于 Octotree 的[码云]文件树插件

      之前一直在用github上面的Octotree,现在在用gitee(主要是github的访问速度太慢了).   现在主要转到了gitee上面了,那么有没有基于 Octotree 的[码云]文件树插 ...

  2. 1级迁移类Q101-Oracle ASM 迁移文件系统(File System)非公

    项目文档引子系列是根据项目原型,制作的测试实验文档,目的是为了提升项目过程中的实际动手能力,打造精品文档AskScuti. 项目文档引子系列目前不对外发布,仅作为博客记录.如学员在实际工作过程中需提前 ...

  3. PyQt5-QDateEdit的简单使用

    使用PyQt5开发图形界面,里面使用日期框,这里把这个QDateEdit组件命名为:beginDate from PyQt5.QtCore import QDate 1.初始化赋值,不设置则默认为20 ...

  4. 2020算法设计竞赛 I、匹配星星

    链接:https://ac.nowcoder.com/acm/contest/3005/I来源:牛客网 天上有n颗星星,每颗星星有二维坐标(xi,yi)(x_i, y_i)(xi​,yi​),还有一个 ...

  5. MySQL | linux中数据库导出和导入

    一.数据库导出(深坑) 命令:mysqldump -u用户名 -p密码 要导出的数据库 > 导出之后的文件.sql mysqldump -uroot -p database_01 > da ...

  6. Codeforces Round #603 (Div. 2) A.Sweet Problem

    #include <cstdio> #include <algorithm> using namespace std; int main() { int t; scanf(&q ...

  7. 杭电oj 2098——分拆素数和(包含如何判断质数及优化),java实现

    question:分拆素数和 思路: 1.首先从1一直遍历到数据的1/2位置(因为后面的会和前面的重复),因为是要两个数,所以另一个数就是原数据减去遍历的数字(即i 和data-i),如果二者同时为质 ...

  8. 记录 shell学习过程(3) if 的格式

    ] #-e 为检测目录或文件是否存在 !为取反 then mkdir -v /tmp/ echo 'ok' fi if else if [ $USER == 'root' ] then echo 'h ...

  9. 较完整checkstyle.xml及说明

    具体项的具体说明请参考:https://www.cnblogs.com/ziyuyuyu/p/9870717.html 梳理此次完整checkstyle.xml说明,以备以后再此基础上删减 <? ...

  10. 持续集成与自动化部署---代码流水线管理及Jenkins和gitlab集成

    1.代码流水线管理 Pipeline名词顾名思义就是流水线的意思,因为公司可能会有很多项目.如果使用jenkins构建完成后,开发构建项目需要一项一项点击,比较麻烦.所以出现pipeline名词. 代 ...