HelloWorld的新写法 in C

HelloWorld的新写法 in C

学习冷知识:Hello World 的 N 种写法,然后为了满足自己好奇心,好好看了看这最后一个程序。

0x1 起源

因为CTF一道题的要求,写出来的c语言不能包含任何括号,这些限制字符包括{[()]}愁坏了孩子

大师傅们想出来的办法是:

# include "/flag"

这样直接编译,会报错输出flag文件的内容:

0x2 思考

上述的解法总感觉不满意。但我也确实没有其他思路,直到找到了开篇的文章。

虽然最后实现的长度过长没办法在题中使用,但是也算是学到了一点东西。

0x3 关于HelloWorld 的不使用{[()]}的方法

博客中给出的代码是:

const int main = 1214185834;
const int main2 = 931213;
const int main3 = 208273408;
const int main4 = 267946330;
const int main5 = 1795109125;
const int main6 = 84891708;
const int main7 = 1819043144;
const int main8 = 1867980911;
const int main9 = 560229490;

编译:

gcc main.c -o main

直接拖进IDA中分析:

当然,数据肯定写在.rodata段,分析称汇编代码,就是输出"Hello World!"

并且在实际调试的时候:

这里确实可执行的。

至于为啥一定要用main这个名字就不多做解释了。

0x5 关于开篇的题的不成熟的想法

至于为啥是不成熟的想法,是因为下面使用的代码确实可以编译执行并读取flag,但是由于题目中长度的输入限制,这代码也判了死刑,有空再改改

//exp.c
const int main = 0x101B848;
const int main1 = 0x1010101;
const int main2 = 0x48500101;
const int main3 = 0x6D672EB8;
const int main4 = 0x1016660;
const int main5 = 0x4314801;
const int main6 = 0x0E7894824;
const int main7 = 0x0F631D231;
const int main8 = 0x0F58026A;
const int main9 = 0x6AC78905;
const int main10 = 0x89485A30;
const int main11 = 0x0FC031E6;
const int main12 = 0x5F016A05;
const int main13 = 0x485A306A;
const int main14 = 0x16AE689;
const int main15 = 0x50F58;

编译测试:

gcc exp.c -o exp

结果:

还得缩短长度。。。咕咕咕🐦

0x6 Reference

冷知识:Hello World 的 N 种写法

posted @ 2020-11-28 15:42  Yisumi  阅读(82)  评论(0)    收藏  举报