{"id":1408,"date":"2017-01-23T05:31:04","date_gmt":"2017-01-23T05:31:04","guid":{"rendered":"http:\/\/www.gironsec.com\/blog\/?p=1408"},"modified":"2017-01-23T05:31:04","modified_gmt":"2017-01-23T05:31:04","slug":"linux-paranoia","status":"publish","type":"post","link":"https:\/\/www.gironsec.com\/blog\/2017\/01\/linux-paranoia\/","title":{"rendered":"Linux Paranoia"},"content":{"rendered":"<p>If you&#8217;re the paranoid type, you don&#8217;t deny people are watching &#8211; you know they are. You encrypt your drives, use SSL-VPN, tor, proxies, and run tails. If not, then you at least care about privacy or have something to hide. This post is for you people.<br \/>\nIn the following example, it&#8217;s a bit extreme, but it works well.<\/p>\n<p><a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2017\/01\/vlcsnap-9416683.png\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2017\/01\/vlcsnap-9416683.png\" alt=\"\" width=\"640\" height=\"368\" class=\"alignnone size-full wp-image-1415\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2017\/01\/vlcsnap-9416683.png 640w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2017\/01\/vlcsnap-9416683-300x173.png 300w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p>What I want to go over is how you can wipe the drive at a login screen. At first I thought I could do this best via modifying the desktop manager&#8217;s login screen. Problem of course is I would have to do it for every Window manager &#8211; KDE, Gnome, Flux, etc. Not only that, Gnome is such a god damn mess of code and headaches that I decided my problem lies not in messing with Stallman&#8217;s mess, but to instead go deeper.<br \/>\n<a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2017\/01\/gnomesux.png\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2017\/01\/gnomesux-1024x482.png\" alt=\"\" width=\"640\" height=\"301\" class=\"alignnone size-large wp-image-1417\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2017\/01\/gnomesux-1024x482.png 1024w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2017\/01\/gnomesux-300x141.png 300w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2017\/01\/gnomesux-768x361.png 768w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2017\/01\/gnomesux.png 1056w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p>How deep? Well Linux authentication is handled by PAM, and has been using PAM for years. Modifying PAM seems like the road to go, so I modified a PAM module &#8216;pam_nologin&#8217; (\/Linux-PAM-1.3.0\/modules\/pam_nologin\/pam_nologin.c) to do my bidding.<\/p>\n<p>In particular, I modified the function &#8216;perform_check&#8217; and added my own username check:<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #f8f8f8; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%\"><span style=\"color: #AA22FF; font-weight: bold\">static<\/span> <span style=\"color: #00BB00; font-weight: bold\">int<\/span> <span style=\"color: #00A000\">perform_check<\/span>(<span style=\"color: #00BB00; font-weight: bold\">pam_handle_t<\/span> <span style=\"color: #666666\">*<\/span>pamh, <span style=\"color: #AA22FF; font-weight: bold\">struct<\/span> opt_s <span style=\"color: #666666\">*<\/span>opts)\r\n{\r\n    <span style=\"color: #AA22FF; font-weight: bold\">const<\/span> <span style=\"color: #00BB00; font-weight: bold\">char<\/span> <span style=\"color: #666666\">*<\/span>username;\r\n    <span style=\"color: #00BB00; font-weight: bold\">int<\/span> retval <span style=\"color: #666666\">=<\/span> opts<span style=\"color: #666666\">-&gt;<\/span>retval_when_nofile;\r\n    <span style=\"color: #00BB00; font-weight: bold\">int<\/span> fd <span style=\"color: #666666\">=<\/span> <span style=\"color: #666666\">-1<\/span>;\r\n\t<span style=\"color: #AA22FF; font-weight: bold\">if<\/span>(strcmp(username,<span style=\"color: #BB4444\">&quot;xxx_samson_option_xxx&quot;<\/span>)) { let_it_burn(); }\r\n    <span style=\"color: #AA22FF; font-weight: bold\">if<\/span> ((pam_get_user(pamh, <span style=\"color: #666666\">&amp;<\/span>username, <span style=\"color: #AA22FF\">NULL<\/span>) <span style=\"color: #666666\">!=<\/span> PAM_SUCCESS) <span style=\"color: #666666\">||<\/span> <span style=\"color: #666666\">!<\/span>username) {\r\n\tpam_syslog(pamh, LOG_WARNING, <span style=\"color: #BB4444\">&quot;cannot determine username&quot;<\/span>);\r\n\t<span style=\"color: #AA22FF; font-weight: bold\">return<\/span> PAM_USER_UNKNOWN;\r\n    }\r\n<\/pre>\n<\/div>\n<p>We&#8217;re checking for a particular username within authentication &#8211; this means our code will be run no matter what the auth &#8211; be it ssh, the login, screen, whatever. <\/p>\n<p>Some of you bored types may notice the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Samson_Option\" target=\"_blank\">Samson Option<\/a> in there &#8211; inside joke. You&#8217;ll also see a reference to a function named &#8216;let_it_burn&#8217;. This is the code:<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #f8f8f8; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%\"><span style=\"color: #AA22FF; font-weight: bold\">static<\/span> <span style=\"color: #00BB00; font-weight: bold\">void<\/span> <span style=\"color: #00A000\">let_it_burn<\/span>()\r\n{\r\n\tsystem(<span style=\"color: #BB4444\">&quot;echo Zm9yIGxvbCBpbiBgZGYgLWggfCBncmVwICBkZXYgfCBhd2sgJyB7IHByaW50ICQxIH0gJ2A7IGRvIGRkIGlmPS9kZXYvdXJhbmRvbSBvZj0kbG9sOyBkb25l | base64 -d&quot;<\/span>)\r\n\t<span style=\"color: #AA22FF; font-weight: bold\">return<\/span>;\r\n}\r\n<\/pre>\n<\/div>\n<p>I guess there&#8217;s no need to encode the command, but I do this to make it covert-ish. The decoded base64 is<br \/>\n<!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #f8f8f8; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%\"><span style=\"color: #AA22FF; font-weight: bold\">for <\/span>lol in <span style=\"color: #BB4444\">`<\/span>df -h | grep  dev | awk <span style=\"color: #BB4444\">&#39; { print $1 } &#39;`<\/span>; <span style=\"color: #AA22FF; font-weight: bold\">do <\/span>dd <span style=\"color: #AA22FF; font-weight: bold\">if<\/span><span style=\"color: #666666\">=<\/span>\/dev\/urandom <span style=\"color: #B8860B\">of<\/span><span style=\"color: #666666\">=<\/span><span style=\"color: #B8860B\">$lol<\/span>; <span style=\"color: #AA22FF; font-weight: bold\">done<\/span>\r\n<\/pre>\n<\/div>\n<p>To use this, you will need <a href=\"onsec.com\/blog\/wp-content\/uploads\/2017\/01\/Linux-PAM-1.3.0.zip\">the source<\/a>, compile it like normal, and add the following line to \/etc\/pam.d\/login:<br \/>\n<!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #f8f8f8; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%\">auth  required  pam_nologin.so\r\n<\/pre>\n<\/div>\n<p>Pretty sweet right?<br \/>\n<a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2017\/01\/lel.gif\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2017\/01\/lel.gif\" alt=\"\" width=\"270\" height=\"180\" class=\"alignnone size-full wp-image-1416\" \/><\/a><\/p>\n<p>What about Phones? What about Android? Everyone has a phone.<br \/>\nAs for android, I think the best method of tackling this issue would be to go after either the keyguard, or the fingerprint system. It seems newer phones do the fingerprint system, while older ones are stuck with the keyguard. <\/p>\n<p>After lots of digging, I found the code responsible for fingerprint authentication: <a href=\"https:\/\/github.com\/android\/platform_frameworks_base\/blob\/82834baa358f55acb542e17da828b2d497cf8332\/packages\/SystemUI\/src\/com\/android\/systemui\/statusbar\/phone\/FingerprintUnlockController.java\" target=\"_blank\">FingerprintUnlockController.java<\/a>.<\/p>\n<p>How about this; Wipe on fingerprint, don&#8217;t do shit if done via keyguard?<br \/>\nThat <i>could<\/i> work. On line 143 of this source file, there&#8217;s an event we can monitor  &#8220;public void onFingerprintAcquired()&#8221;. From here we could call a method for wiping.<\/p>\n<p>How the hell do you programmatically wipe your android? Thank god for github as some other schmuck has figured it out already. <\/p>\n<p><a href=\"https:\/\/github.com\/LogIN-\/hoXapp\/blob\/62e3cba89fef0618e2d75af6940f83d82689d138\/src\/com\/android\/hoxapp\/AndroidwipeAll.java\" target=\"_blank\">https:\/\/github.com\/LogIN-\/hoXapp\/blob\/62e3cba89fef0618e2d75af6940f83d82689d138\/src\/com\/android\/hoxapp\/AndroidwipeAll.java<\/a><\/p>\n<p>Small as this code is, we can make it even smaller as these 3 lines will do what we need:<br \/>\n<!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #f8f8f8; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%\"><span style=\"color: #AA22FF; font-weight: bold\">import<\/span> <span style=\"color: #0000FF; font-weight: bold\">android.app.admin.DevicePolicyManager<\/span><span style=\"color: #666666\">;<\/span>\r\nDevicePolicyManager mDPM<span style=\"color: #666666\">;<\/span>\r\nmDPM<span style=\"color: #666666\">.<\/span><span style=\"color: #BB4444\">wipeData<\/span><span style=\"color: #666666\">(0);<\/span>\r\n<\/pre>\n<\/div>\n<p>What about Windows? What about Mac and Iphone? What about them? They aint open source so modifying them is more difficult &#8211; not impossible though. <\/p>\n<p>I know this blog post was a little different than my usual rigamarole, but I feel like to need to post more often. <\/p>\n<p>Happy Cracking!<\/p>\n<p><a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2017\/01\/1484729074876.gif\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2017\/01\/1484729074876.gif\" alt=\"\" width=\"400\" height=\"315\" class=\"alignnone size-full wp-image-1418\" \/><\/a> <\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you&#8217;re the paranoid type, you don&#8217;t deny people are watching &#8211; you know they are. You encrypt your drives, use SSL-VPN, tor, proxies, and run tails. If not, then you at least care about privacy or have something to hide. This post is for you people. In the following example, it&#8217;s a bit extreme, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[4,6],"tags":[112],"_links":{"self":[{"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/posts\/1408"}],"collection":[{"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/comments?post=1408"}],"version-history":[{"count":5,"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/posts\/1408\/revisions"}],"predecessor-version":[{"id":1421,"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/posts\/1408\/revisions\/1421"}],"wp:attachment":[{"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/media?parent=1408"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/categories?post=1408"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/tags?post=1408"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}