0%

国赛pwn修复2

题目修复部分

题目的点很容易看出,数组越界,不过如何利用这个比较难,我经过一段时间测试,发觉scanf的特性,输入-可以绕过,所以可以泄露cannary,泄露cannary过后可以任意写,然后精确覆盖到cannary过后进行ROP就行了,还有一个点就是输入长度为27的时候,他不会进行排序,这样才能ROP,不过最终我没利用成功,还有一个栈的偏移点我还没搞懂,所以最终也没打出来

修复建议:在读和写的时候都限制数组长度,还有排序的时候考虑长度为27的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int cmp(const void *a1, const void *a2)

{

return (int)(*(int *)a1 - *(int *)a2);

}

void sub()

{

char v1;

char v2;

printf("do you would to sort your girlfriends?[Y/N/@]");

scanf("%c", &v2);

if ( v2 == 78 )

{

printf("goodbye~~~");

exit(0);

}

if ( v2 == 89 )

{

printf("goodbye~~~");

exit(0);

}

if ( v2 != 64 )

exit(0);

puts("please answer two questions!");

puts("1+1999=??\n");

puts("please answer the question1:");

scanf("%c", &v1);

puts("1*1999=??\n");

printf("please answer the question2:");

scanf("%c", &v1);

if ( v1 != 94 )

exit(0);

puts("you are right~\n");

}

void sub2()

{

char buf;

puts("my girlfriend,today is very interesting!!! ");

puts("nice to meet you!");

puts("here is a pole! \n");

printf("please input your name:");

read(0, &buf, 0x10uLL);

puts("hello my destiny!\n");

}

void sub1()

{

int v2; // [rsp+4h] [rbp-4Ch]

int i; // [rsp+8h] [rbp-48h]

int j; // [rsp+Ch] [rbp-44h]

int k; // [rsp+10h] [rbp-40h]

int v6; // [rsp+14h] [rbp-3Ch]

int v7; // [rsp+18h] [rbp-38h]

int v8; // [rsp+1Ch] [rbp-34h]

int base[10];



v6 = 0;

v7 = 999;

puts("how many girlfriends do you have?");

scanf("%d", &v2);

if(v2 > 10 || v2 < 0)

{

exit(0);

}

for ( i = 0; i < v2; ++i )

{

printf("please input your %dth girlfriends:", i);

scanf("%d", &base[i]);

}

if ( v7 != 999 )

exit(0);

qsort(base, v2, 4uLL, cmp);

printf("this is the sort result:");

for ( j = 0; j < v2; ++j )

printf("%d ", (unsigned int)base[j]);

puts("you can change your girlfriend");

scanf("%d", &v2);

v8 = v2;

if ( !v2 )

{

printf("which girlfriend do you want to change?");

scanf("%d", &v2);

if(v2 > 10 || v2 < 0)

{

exit(0);

}

for ( k = 0; k < v2; ++k )

{

puts("now change:");

scanf("%d", &base[k]);

}

}

if ( v2 <= 79 && v2 > 39 )

qsort(base, v2, 4uLL, cmp);

if ( v2 <= 100 && v2 > 80 )

qsort(base, v2, 4uLL, cmp);

if ( v2 <= 64 && v2 > 55 )

qsort(base, v2, 4uLL, cmp);

if ( v2 <= 100 )

{

if ( v2 <= 27 || v2 > 39 )

{

if ( v2 <= 26 )

qsort(base, v2, 4uLL, cmp);

else

qsort(base,v2,4uLL,cmp);

}

else

{

qsort(base, v2, 4uLL, cmp);

}

}

else

{

qsort(base, v2, 4uLL, cmp);

}

}

int main()

{

//sub();

//sub2();

sub1();

return 0;

}

本文作者:NoOne
本文地址https://noonegroup.xyz/posts/5755f899/
版权声明:转载请注明出处!