<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by b33f_k4r4g3#kazuya on Medium]]></title>
        <description><![CDATA[Stories by b33f_k4r4g3#kazuya on Medium]]></description>
        <link>https://medium.com/@tornadohenky1?source=rss-c50b97cf5cb9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*0BR15LB-ym-Z6yuZpW2L1w.png</url>
            <title>Stories by b33f_k4r4g3#kazuya on Medium</title>
            <link>https://medium.com/@tornadohenky1?source=rss-c50b97cf5cb9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 00:47:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tornadohenky1/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Modbus Communication tcp/ip at Smart relay using Zeliosoft2]]></title>
            <link>https://medium.com/@tornadohenky1/modbus-communication-tcp-ip-at-smart-relay-using-zeliosoft2-8eb1fad9768f?source=rss-c50b97cf5cb9------2</link>
            <guid isPermaLink="false">https://medium.com/p/8eb1fad9768f</guid>
            <category><![CDATA[zelio-soft]]></category>
            <category><![CDATA[zelio-logic]]></category>
            <category><![CDATA[smart-relay]]></category>
            <category><![CDATA[modbus]]></category>
            <dc:creator><![CDATA[b33f_k4r4g3#kazuya]]></dc:creator>
            <pubDate>Wed, 19 Jun 2024 14:42:20 GMT</pubDate>
            <atom:updated>2024-06-19T14:42:20.549Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi guys, long time no see, Today i wanted to write something that i have been researching from 2 month, Originally i am a penetration tester, but when my company want to go to the scada i have been research about it and trying to make one. The things why i want to write this article is because you know searching this one is like a hell at google or youtube so i wanted to write a complete one for you :-).</p><p>So first what I am using for this one is:</p><p>hardware:</p><p><strong>SR3 B101BD</strong> -&gt; is the smart relay</p><p><strong>SR3 NET101BD</strong> -&gt; is the extension module for allowing the smart relay communicate using the modbus tcp/ip.</p><p><strong>SR2 USB 01</strong> -&gt; this the cable that you need to use for upload the code from the computer to your device (smart relay).</p><p>for software to code the smart relay, i am using <strong>zeliosoft 2 </strong>(<a href="https://www.se.com/id/id/download/document/ZelioSoft2/">https://www.se.com/id/id/download/document/ZelioSoft2/</a>).</p><p>for modbus communication, we will use,</p><ul><li>python and using library <strong>umodbus (</strong><a href="https://umodbus.readthedocs.io/en/latest/">https://umodbus.readthedocs.io/en/latest/</a><strong>).</strong></li><li>but if you want to use the GUI one you can use: <strong>QmodMaster.</strong></li></ul><p>Now let’s go to detail, for code at smart relay we will use FBD, so what is FBD (Function Block Diagram), is graphical language for programmable logic controller design, that can describe the function between input varibles and output variables. ref: <a href="https://en.wikipedia.org/wiki/Function_block_diagram">https://en.wikipedia.org/wiki/Function_block_diagram</a>.</p><p>for the objective I will create the simple one for you and explain how the wiring will be done. our objective is receive the button input to modbus and send back the prompt to turn on the indicator lamp.</p><p>for the button wiring will looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/843/1*GFmdXiRV4dbof3k3kTEkLg.png" /><figcaption>Button wiring to PLC</figcaption></figure><p>in this case, usually the button is not having the +/- so it’s depends on your choice but still you need to read it first what button you will use, in my case i am using the momentary button, the wiring explaination:</p><ul><li>the (-) from the button will go to I1, remember that I(n) is used for input in PLC.</li><li>the (+) part will go to the power outlet at our SR3 B101 BD.</li></ul><p>for the lamp wiring will looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PSRyPBZFsGZJHcibzPKGBQ.png" /><figcaption>Lamp indicator wiring.</figcaption></figure><p>in this case you can use indicator lamp that you are prefer and usually for the +/- is not designed so it depends on us how we want to create the wiring, for detail explaination:</p><ul><li>Button, the (+) from button will go to our SR B101 BD power outlet to get the electric power.</li><li>Button, the (-) from button will go to the Q1 (Left side), anyway Q1 or Q(n) usually used for the output at the PLC and do not be panic if you cannot output anything since we need to wire the power at right side.</li><li>for the Q1 we need to wire the right side to our power outlet, we can use the (-) part to the right side to enable the electric power so our lamp will be turn on when we code it.</li></ul><p>For the SR3 NET01 BD, it will looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*rI83HNt68tqYSt-KObsFxg.png" /><figcaption>SR3 NET01 BD installation</figcaption></figure><p>in this case you are just needed to open the small cover at SR3 B101 BD and plug the SR3 NET01 BD at there.</p><p>anyway we need to use the cable to upload our code from the computer to smart relay, where it plugged is at here just in case:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/250/1*RDP78SppCwGKUYMgDVqY2w.jpeg" /><figcaption>For SR2 USB01.</figcaption></figure><p>the detail is well you are just needed to open this cover and plug in the SR2 USB01 at SR3 B101 BD and plug the USB to the computer.</p><p>Now let’s go to the programming phase, i will try to explain it as detail as possible.</p><p>first we need to define our device at the zelio soft below is the screenshot:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n1g32qmz8KjU9NTTCZhr7Q.png" /><figcaption>zelio soft select the compatible device.</figcaption></figure><p>after we create a new project, select the PLC device that you use, in this case we will use SR3 B101 BD, next is select the extension that we will use in this project, below is the screenshot:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pNhaD1D1gVcu7VJskYW45w.png" /><figcaption>select the extension.</figcaption></figure><p>for this case we will select the SR3 NET01 BD, to be able to use the modbus for the communication.</p><p>for the notes we must now that when you first using the SR3 B101 BD you will have to update the firmware first, since in this case we will use FBD not the ladder logic, so if you try to upload it you will encounter error. when you encounter it the reason is because the basic firmware that installed on the first buy is only using the ladder logic, so the step is you need to:</p><ul><li>STOP the module first.</li><li>At zeliosoft 2 you need to select the module &gt; update firmware, after done it will popup something like this.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_nWeBvg2x9gVbR3CszusdQ.png" /><figcaption>Update the firmware.</figcaption></figure><p>you need to select FBD-SFC and voila now you can upload the FBD program to your PLC.</p><p>After you go to the project view, now we need to setup our ip first at zeliosoft, this ip will become the ip of your PLC, the step is quite simple, you need to go edit &gt; program configuration &gt; ethernet extension</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pf6i01Lzu47D-YXSukSXvw.png" /><figcaption>IP configuration.</figcaption></figure><p>after it’s done you may upload it just in case to see the IP is configuration properly, you can try to ping the designed IP.</p><p>Now let’s go to the code, it’s quite simple since the object is only the button and the lamp. we will use some component like integer input, integer output, discrete input, discrete output, bit to word conversion and word to bit conversion.</p><blockquote><strong>Discrete input/output</strong> is the presence of the status on/off for electric signal.</blockquote><p>first for the button configuration the code will looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hm1wxhTuKoqswlNieZT7Dw.png" /><figcaption>button code.</figcaption></figure><p>The explaination for button code, this is per point explaination:</p><ul><li>B000 label, in this case we will use discrete input to get this function code you need to go to <strong>IN button</strong> and drag and drop the same symbol to the I1. After it’s done now we know when the button sending the electric signal of on status or off status usually it will be looks like an boolean on our zeliosoft 2.</li><li>B002 label, is the <strong>bit to word conversion</strong> we will need to use this to convert from discrete input to the integer since the output that can be send or receive from modbus is only for integer. this function is located at <strong>FBD button </strong>and from there you need to select the bit to word conversion.</li><li>B001 label, is the modbus output at zeliosoft 2 and in this case we can only use <strong>integer output</strong> for this case drag the function to the <strong>O1 XT1</strong>. to get this function code you only need to go to the <strong>OUT</strong> and select the same label as mine.</li></ul><p>After the button code is done now we need to define our lamp the code will looks like this, below is the screenshot and explaination:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ns4A-CKG7UFMnVVElaLSSA.png" /><figcaption>Lamp code.</figcaption></figure><p>This is the per point explaination about the lamp code:</p><ul><li>B003 label, is used for modbus input and as i explain before that we can only send/receive the integer so we need to use the integer input in this section, to get this function you need to go to the <strong>J1 XT1.</strong></li><li>B005 label, is used for convert our integer to the discrete output, this function is called word to bit conversion, to get this function you need to go the <strong>FBD button</strong> and get same label as mine.</li><li>B004 label, is our output for the lamp in this case we are going to say to our PLC <em>“hey i just got the prompt from modbus to turn on the lamp”</em>, to get this function you just need to go to <strong>OUT button</strong> and select the <strong>discrete output</strong>.</li></ul><p>After the code is done, now all you need to do is transfer your program to the PLC, you can do this by select transfer &gt; transfer from PC to PLC.</p><p>Now before we are going to the server simulator, you need some knowledge about why we use J1 XT1 and O1 XT1, let me explain it below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q6KtK7nD-z3A1omEwM80Fw.png" /><figcaption>input and output for modbus.</figcaption></figure><ul><li>J1 XT1, J2 XT1, J3 XT1 and J4 XT1 is used for modbus input and do not forget that you can only transfer the integer variable through modbus tcp/ip communication.</li><li>O1 XT1, O2 XT1, O3 XT1 and O4 XT4 is used for modbus output and again we can only use the interger output for this case.</li></ul><p>Now the important part since in the <strong>python</strong> or <strong>QModMaster</strong> we need to have the address to get the input or output below is the listed address for each section.</p><p>Modbus input section:</p><ul><li>J1 XT1 =&gt; 16</li><li>J2 XT1 =&gt; 17</li><li>J3 XT1 =&gt; 18</li><li>J4 XT1 =&gt; 19</li></ul><p>Modbus output section:</p><ul><li>O1 XT1 =&gt; 20</li><li>O2 XT1 =&gt; 21</li><li>O3 XT1 =&gt; 22</li><li>O4 XT1 =&gt; 23</li></ul><p>for the communication we are using the python code to receive the button value and then trigger the lamp to on, from the button or switch. you can try to using 2 PLC/Smart Relay to implement the communication between the PLC, in the simpler case we can also directly using schneider electric Smart PLC M221, how ever in this case i am trying it using one PLC for now actually i am using s7–1500 from siemens to create the communication like this but maybe i will describe more on next article.</p><p>Below i attached my python code to run the modbus client communication.</p><p>There is some of the built in function that used for reading or writing the values at modbus:</p><ul><li>01: Read Coils</li><li>02: Read Discrete Input</li><li>03: Read Holding Registers</li><li>04: Read Input Registers</li><li>05: Write Single Coil</li><li>06: Write Single Registers</li><li>15: Write Multiple Coils</li><li>16: Write Multiple Registers</li></ul><p>In this case we will only use <strong>Write Single Registers</strong> and <strong>Read Holding Registers</strong>, since in our FBD we are having the value as the register and the values stored as integer value. since the value is stored now we need to read the value from the button and write the value to trigger the lamp condition.</p><pre>import socket<br>from umodbus.client import tcp<br>from umodbus import conf<br><br>conf.SIGNED_VALUE = True<br><br>sock = socket.socket(AF_INET, SOCK_STREAM)<br>#change the IP part if you set it different<br>sock.connect((&quot;192.168.0.101&quot;, 502))<br><br>#here is how the command looks like for the write_single_register <br>#slaveid=1, address=16 (depends on where will you put the value), value=0 is the state since it&#39;s boolean it&#39;s only 1 or 0<br>command_lamp_off = tcp.write_single_register(slave_id=1, address=16, value=0)<br>command_lamp_on = tcp.write_single_register(slave_id=1, address=16, value=1)<br><br>#here is how the command looks like for read_holding_register<br>command_button_status = tcp.read_holding_registers(slave_id=1, starting_address=20, quantity=1)<br><br>#below is how my logic looks like, so when the button is pressed the value will be 1 and i wanted to turn on the lamp<br>while 1:<br>    button_status = tcp.send_message(command_button_status, sock)<br>    if button_status[0] == 0:<br>        tcp.send_message(command_lamp_off, sock)<br>    elif button_status[0] == 1:<br>        tcp.send_message(command_lamp_on, sock)<br>    else:<br>        tcp.send_message(command_lamp_off, , sock)</pre><p>Maybe this is all from me, Please let me know if there is something wrong or needed evaluation, i am still learning too and i am not gonna lie this stuff is fun, I will write more about how to connect pt100 to zelio and the part where we bridging the communication from this smart relay to the siemens s7–1500. Thank you so much for taking your time to read this article :D</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8eb1fad9768f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Malware analysis overview]]></title>
            <link>https://medium.com/@tornadohenky1/malware-analysis-overview-6737e895e118?source=rss-c50b97cf5cb9------2</link>
            <guid isPermaLink="false">https://medium.com/p/6737e895e118</guid>
            <category><![CDATA[malware-analysis]]></category>
            <category><![CDATA[reverse-engineering]]></category>
            <dc:creator><![CDATA[b33f_k4r4g3#kazuya]]></dc:creator>
            <pubDate>Mon, 08 Jun 2020 16:10:34 GMT</pubDate>
            <atom:updated>2020-06-08T16:10:34.596Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><blockquote>malware, malware oh malware, oh shit my computer have been infected by an malware &gt;_&lt;</blockquote><p>People in this digital revolution era, makes everything connected, back there in the past, when we want to communicate with someone, we need to send a message using a dove, after that people are starting to create a service that can send your message using a letter and then the pos man will deliver the letter and then they change it into some technology called telegraph that can send a message using the telegraphy technique or send a message with a long distance using the telegraphic codes, people keep moving until now we can send a message from our smartphone, my point is our technology keeps moving forward but sometimes people don’t seem to be aware of the flaw of the technology that can cause a loss for a lot of people.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IhuFqxKuPfWSoN03.jpg" /><figcaption><a href="https://www.wallpaperup.com/1310619/Connected_v2_-_network_dot_connections_wallpaper.html">https://www.wallpaperup.com/1310619/Connected_v2_-_network_dot_connections_wallpaper.html</a></figcaption></figure><p>the flaw of the technology becomes more serious than we thought, have you ever think the flaw of technology could kill a person or making all your money loss in one second or is it make sense if one flaw of the almighty technology that human create can shutdown certain nation just because of one error, one flaw, or a simple mistake that called human error. let’s take a look to something that is more awesome.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zLtutWz6OOkt7KOj.jpg" /></figure><p>This malware or computer worm, that built jointly between US and Israel, our little friend is specifically targeting the PLC (Program Logic Controller) which allow the automation of electromechanical processes such as something that controlling machinery and industrial process including gas centrifuges, with exploiting the STEP7 zero day, just imagine it this malware could infect 200,000 computers and caused 1,000 machines to physically degrade, let us discuss about what happened in STUXnet incident, this is not just a simple malware, deep inside this malware having the 3 modules:</p><p><strong>a worm </strong>that executes all routine to inject the payload and the function, <strong>a link file </strong>that automatically executes the propagated copies of the worm and <strong>root kit</strong> that will hide all process and file too make sure that no one can detect it.</p><p>so in this article, I want to breakdown the malware analysis(STUXNet) using static analysis approach and explain some of them.</p><h3>Malware</h3><p>Let’s explore deeper inside “malware”, what is malware? Malware is technically a software that intentionally created to cause damage to any computer, system, network, and client. But we can also define it as a program or software that intentionally created to cause serious damage to Confidentiality, Integrity, and Availability in the system or computer.</p><blockquote>Here is some ambiguous question for you, <strong>what the difference between malware and virus?</strong></blockquote><blockquote><strong>Answer</strong>: malware and virus are different after all, we will discuss the general and specific concept, first malware is designed to crash or to cause some damage to CIA but the Virus is created and designed to change the flow of the system, here is a metaphor about a virus, the virus that infects human are having the same concept with the virus that infects a system, how they are same? If we discussing about influenza virus that can cause damage to human nose, it can change the usual flow, from how nose usually work, when you are inhale you take the O2 but when you are exhale you are release some CO2, here is the infected flow when you are inhale you are taking some O2 but when the mucous membrane are trying to filter the CO2 in your inhale breath it will produce a lot more mucus that will make you have a problem when you are taking a breath and release the breath, this concept is just a same with the virus in our computer system when you actually run the PDF it will show the content of the file but now imagine if you are downloading the malicious PDF with something inside and when you open the file, it will cause something that not usually happen when you open the PDF let’s say it’s contain something that can modify the registry on your operating system and caused damage that can make your operating system can’t boot because maybe there is a part that has been deleted by the virus. but the conclusion is :</blockquote><blockquote>“Virus is a type of malware, but malware is not a virus it can be everything that causing damage to your system”</blockquote><h3>Malware analysis Introduction</h3><p>malware analysis is important for industry and we can create an countermeasure for malware and then make them perish, just like what happen in the pandemic like COVID-19.</p><p>because of it, every nation will compete to develop the vaccine, they will analyze the virus from the form, behavior, how they infect a human, or how this virus spread after infect their target, and what this virus cause after they are infecting some people. If you compare it to what we do in the malware analysis it will have the same procedure. When we found a malware that infects the computer or maybe takes down our system, we need to analyze it to make the countermeasure for taking care of this malware.</p><h3>Malware analysis types</h3><ul><li>Static malware analysis</li></ul><h4>Static malware analysis</h4><p>static or code analysis usually in here we should analyze this step without execute the binary, so if we take a look deeper inside the static analysis we will discuss about file segment, file header, signature file, magic number and something that have a connection to an file, you can approach it using the assembler too, people are calling it disassembler because it simply just create a compiler from the targeted your executable to estimated machine code, i want to break down some part in this paragraph, some of them are really important for your basic on reverse engineering.</p><p>first let us know about how <strong>compiler </strong>work, i am create a simple illustration for you to know how it works.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hbNAVOlSzL-z8gfdTSw2Fg.png" /><figcaption><strong>compiler illustration</strong></figcaption></figure><p>it will always like this, to make it easy to understand just imagine that this compiler is more like the translator between different kind of language, i will explain more detail about how compiler work in my next article and then after that let us back to the topic. so what is disassembler and how it works, i will create a simple illustration for you.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aNgg_GxQ9bfntiHU6Dfz6g.png" /><figcaption><strong>illustration of disassembler</strong></figcaption></figure><p>simply about how it works when you have kind of file whether it’s executable or .PNG or something like .ZIP it will tear down and created estimated packed binary to their assembly instruction. but first it will read the header file and decide what is that file. example: ELF(executable and Linking Format for linux/unix) in their hex it will looks like 7F 45 4C 46 this, you can learn more about file header in <a href="https://en.wikipedia.org/wiki/List_of_file_signatures">here</a>. if you want to see this you can use hex editor like HxD and it will looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8sTiY4ttz8MjdwRcL4g9OQ.png" /><figcaption>HxD preview</figcaption></figure><p>but it’s not just HxD you can see the hex number in online tools too <a href="https://hexed.it/">https://hexed.it/</a> after that all you need to do is just drag the file to this tools.</p><p>let us move to disassembler, well there is a lot tools that can do this disassembler things, but i recommend you to use IDA Pro or Ghidra. i recommend them because IDA Pro and Ghidra are more user friendly than other tools, i will explain about them below, let me start my report about static malware analysis in STUXnet.</p><h3>Requirement</h3><p>remember this one never use your real device when you are doing malware analysis, at least you can use an Virtual Machine or setup your sand box.</p><p>but in my case i am using virtual machine or VMware, since we are not doing behavior monitoring then it will more simple. let’s get to the tools, for doing this you need to use IDAPro or Ghidra or another tools that you are comfortable with.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DJfjbdjt0CC1nN2oz5QRpQ.png" /><figcaption>my settings for my VMWare</figcaption></figure><p>and i am used ubuntu just for setup, but if we want to analyze the behavior i recommend that we using windows XP or windows 7 as the based OS at VM.</p><h3>Hands on Malware analysis(static analysis)</h3><p>i got the malware sample from :</p><p><a href="https://www.codeproject.com/KB/web-security/StuxnetMalware/MRxNet.zip">https://www.codeproject.com/KB/web-security/StuxnetMalware/MRxNet.zip</a></p><h4>Stuxnet Root Kit(Static Analysis in kernel mode)</h4><p>i want to start analyze it from the root kit section:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*jbEO2zu5G3oG-00ImUVQyA.png" /><figcaption>sample file.</figcaption></figure><p>at first look we can find the source code and the sample file that compiled from the main.c and fastlo.c, i will explain about them in the end, because we need to analyze the sample first, in real condition all we can retrieve from the evidence will be just the mrxnet.sys, we can’t get the real source code or their mock up, so let’s start from the .sys, first step is you must know what kind of file that you analyze in, so you can use the specific disassembler to make it more easier to read, in linux we can analyze it using the <em>file </em>to determine what is this file, sometimes you can get the extension less file so before you try to make anything to them the first thing that you need to do is analyze what kind of file that you are currently want to analyze, you can use <em>file </em>in linux it will looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/591/1*MlAO0tQCDSusvnbTEk_o3Q.png" /><figcaption>file type</figcaption></figure><p>anyway you can use radare2 for checking this file it will show you everything about this file information just run it and use “iI” command and it will looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/529/1*CzAnkkXSdXkZ0LaphKMPKg.png" /><figcaption>R2 result</figcaption></figure><p>or if you want to using manual technique you can use text editor or hex editor to open it and go to the file header segment and you will what is this file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/531/1*qMPBNN8xrMQ0flWfmxW_IQ.png" /><figcaption>File signature</figcaption></figure><p>usually in here you must remember if you are seeing something like 4D 5A or in string MZ it will be DOS MZ executable, it’s usually the signature that showing the .EXE file in DOS so if you are seeing this MZ thing than you can make sure that if this file is running on DOS environment but to make sure that if this is PE or not you can use the tools called <em>detect it easy </em>it will looks like :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/622/1*dSgJK5c4FhUZdsCkGG-ZVg.png" /><figcaption>detect it easy result</figcaption></figure><p>let’s go to analyze the logic of Stuxnet root kit, for today i will use IDAPro because the result is more easy to understand. first we will see something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2aDwkYDjcarGmcVKU9wK_w.png" /><figcaption>IDA Pro first sight</figcaption></figure><p>i need two or three days to create a map for the function and still not finished and i am not see the real sample source code it’s pure from the sample file, well it’s not easy, the first thing that you must look is why when we disassemble this file the function become sub_1108C or something like that,</p><blockquote>is the compiler or the IDA pro broken ?</blockquote><p>the answer is no man, this is what you called <strong>stripped binary </strong>what is this and how to see them, first stripped binary isn’t contain the debugging information or debugging symbol it will makes an reverse engineer having an hard time because all function name is altered to “sub_&lt;something&gt;”, but stripped binary is having better performance than non stripped binary, because of the size and they are reduced the debugging symbol, you can see them in file information or use radare2.</p><p>after that to analyze this you need to know the file section, you can trace the string from the .rdata(read only initialized data) and .data(initialized data(free format)), in .rdata you can find some data that means to be read only in that program you can find somethings like :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/877/1*qRfWRrp-SeL78O8WuQ1Qlg.png" /><figcaption>rdata file sample</figcaption></figure><p>in here you can find something like PDB file name, or debug information, but in .data you can find some initialized data so if there is a byte or array and it’s initialized like char a[1] = “a”;, you can find it inside here, the segment will looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*4g-x-myhzoD-BwDxL-nz-w.png" /><figcaption>data file segment</figcaption></figure><p>enough with recon and tracing string, so first thing that i got from this root kit sample i got the function that used to attach device and the main function that will make decision to attach or detach the device.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/791/1*Y71Lr4zCS0kCdG84RkFopA.png" /><figcaption>assembly flow</figcaption></figure><p>wait you can compile it to pseudo code that will looks like C and it will looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/488/1*el1MjpLSSy2yjyDo8diCqw.png" /><figcaption>pseudo code</figcaption></figure><p>by the way i am using IDAPro V7.0, as you can see <em>sub_109EC </em>is the function that used to decide it will attach the file or delete them, cool right ! yeah, this is how it works, so first is if a2 decide to attach the device than it will go to attach device function or <em>sub_10980 </em>but if the condition is not to attach then it will go to else segment, to keep it simple this condition are to detach and then delete the file from the device and it will go to next attached device to keep detach it until all of attached device is detached.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/475/1*oWbqwnPXF53PP08FgJqKUA.png" /><figcaption>delete and detach logic</figcaption></figure><p>have you realize something ?, the concept is more like data structure or linked list and this is using the single linked list logic, it will keep looking to the next attached device, if i were to make some example it will looks like:<br>TargetedDevice -&gt; AttachedDevice -&gt; AttachedDevice -&gt; AttachedDevice -&gt;NULL.</p><p>but inside the looping there will be a validation to check if we are currently inside our own device or not.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/483/1*Wv30kHmrGtnZzAJtrd4j-w.png" /><figcaption>checking current device</figcaption></figure><p>let’s go to the how this Stuxnet attach to your device, the pseudo code will looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/775/1*nm4RAP2X-J-ToZwCneR6AA.png" /><figcaption>attach device function</figcaption></figure><p>Stuxnet will not attach all device, as you can see in this part:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/409/1*64lt7nsv_19mZnQgB4pKTg.png" /><figcaption>a part of attach device function</figcaption></figure><p>after i am doing some research about it i find that if Stuxnet will attach device if the device type is :</p><blockquote>0x0000008 is stand for FILE_DEVICE_DISK_FILE_SYSTEM</blockquote><blockquote>0x0000003 is stand for FILE_DEVICE_CD_ROM_FILE_SYSTEM</blockquote><blockquote>0x0000014 is stand for FILE_DEVICE_NETWORK_FILE_SYSTEM</blockquote><p>after this Stuxnet will decide if the device is already attached or not it’s in <em>sub_10AB4</em> and it will looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/636/1*CafK_xrdjDTZUU9pMZ6Igw.png" /><figcaption>attached device</figcaption></figure><p>i got something from my research about this you can read it <a href="https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/ns-wdm-_device_object">here,</a> so if the device is attached and loaded then the Driver Object should have his value and in here if they are loaded or not for this you can read it <a href="https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/ns-wdm-_driver_object">here</a>. after this process Stuxnet will validate if they success to create the device is located in function sub_10A3C and it will looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/666/1*gGruJuo0PbwdvT4FCA9PvQ.png" /><figcaption>create device function</figcaption></figure><p>yeah this function is just wrapping the <a href="https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/nf-wdm-iocreatedevice">IoCreateDevice();</a></p><p>after that if the criteria of the validation is okay, i will setup the value first for component inside the DeviceObject and it will set Device extension to zero in <em>sub_10A92</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/344/1*OMDSOg-FF_c_KfJKCPGmCg.png" /><figcaption>sub_10A92</figcaption></figure><p>after that Stuxnet will check first if the they are already attached on the device stack or not the function will looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/651/1*xGqmM4skwZlawyJQWHovVA.png" /><figcaption>sub_10B12</figcaption></figure><p>after that if the result is not zero then this function will return the value and attach device function will delete it, if not it will go to the upper function.</p><p>well day 2, i found if there are some function to attaching object or payload before they call the attach function and the main function that will make decision to attach or detach the device, the initiator for detecting the driver and for hook the file system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*bQ2N65t2CZeOURkmdFgebA.png" /><figcaption>sub_10726</figcaption></figure><p>if you are doing static analysis and do it in kernel mode, then this should be the first thing that you are checking, because after this function it will lead the way to all of the important function in here, because this function is having the control over the file system and directory control, how can i know about this it’s from the :</p><blockquote>DriverObject-&gt;MajorFunction[13] that stands for IRP_MJ_DIRECTORY_CONTROL.</blockquote><blockquote>DriverObject-&gt;MajorFunction[14] that stands for IRP_MJ_FILE_SYSTEM_CONTROL.</blockquote><p>you can read about it <a href="https://www.aldeid.com/wiki/DRIVER_OBJECTc">here</a>.</p><p>let us focus to the hook_file(), i am already renamed it, so it will be easy to trace the flow. so in hook_file() function at first it will looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/511/1*RAcn-0ZWIFCswg8RMdxalg.png" /><figcaption>hook_file</figcaption></figure><p>after that it will go to attach_initiator i renamed it too, inside the attach initiator it will looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/878/1*w_9g9JGAmPmXUAZR8gcL4A.png" /><figcaption>attach initiator</figcaption></figure><p>in here you will see the <em>sub_109EC(i,1)</em>, so if a2 in sub_109EC is having the value then it will launch the attach device function, it will keep attach the object to the next device.</p><p>day 3 and day 4 i got the function that often used for checking file function, controlling file system and directory control. i can trace it from sub_10726 there are some signature that showed for directory control and file control, as you can see when the program called DriverObject and point it to specific array they called some function <em>sub_10496</em> and <em>sub_104EC. </em>sub_10946 is for file system control and sub_104EC is for directory control.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*KeoqbMIPCkpa169sQkhM4w.png" /><figcaption>file system control</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/441/1*8KXZOGCHh_3eYL-3rpE2xA.png" /><figcaption>directory control</figcaption></figure><p>at first i think huh this just about comparing something inside the Irp and execute the function. but it’s not like that let’s take a look at the simple image about how IRP work:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/403/1*_MRfWs3krr_P5RPAnrRbmQ.jpeg" /><figcaption>IRP structure resource: <a href="https://www-user.tu-chemnitz.de/~heha/oney_wdm/ch05b.htm">https://www-user.tu-chemnitz.de/~heha/oney_wdm/ch05b.htm</a></figcaption></figure><p>in here the validation will check the overlay section and keep checking the packet type and check whether it’s equal to 1 or not.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/1*_YAkKjLYKed8LCUFRU3Shg.jpeg" /><figcaption>tail overlay resource : <a href="https://www-user.tu-chemnitz.de/~heha/oney_wdm/ch05b.htm">https://www-user.tu-chemnitz.de/~heha/oney_wdm/ch05b.htm</a></figcaption></figure><p>well here is a little explanation for you, IRP is used for controlling I/O request inside the kernel, example if i have a block device and it want to read something then the block device will generate IRP and send it to file system to check the IRP to look into the data.</p><p>explanation for file system control and directory control the function work more looks like it will compare to something and keep checking your file system and directory so here is how it will looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/877/1*Y139RVsVJVVZb47rDA-2xw.png" /><figcaption>file system control</figcaption></figure><p>so if the condition one is true it will go inside the sub_10906 for the file system control and then it will search something and keep looking inside the IRP overlay section, as for the directory control there is something smell fishy, at first look the function will looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/615/1*nenspTXtmCTNpEqAUVYXLg.png" /><figcaption>directory control function</figcaption></figure><p>in here as we can see, this function is try to find an directory find the directory and hide it, at first i confused because of the <em>memcmp(*(…)(v4+4), “{“, 0x4c)</em>, after i am tracing the string that compared, i find the string that looks like GUID don’t know, but somehow Stuxnet is making the possible way to hide this directory inside your device, the string will looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/1*1l8wKN1pVKGzcgKskk9qhQ.png" /><figcaption>that 5876 something it’s the targeted directory</figcaption></figure><p>and after that i am focused to the complete routine function, it will looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/681/1*iI4GuPc0eC8BNKf4kpyv7w.png" /><figcaption>sub_102CA part 1</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/588/1*rDlwX9cQ4WOy8uj-iULJWQ.png" /><figcaption>sub_102CA part 2</figcaption></figure><p>do you know paging system in kernel operation ? yeah buddy system and friends i won’t explain about them because it will make this medium become more complicated, but the simple way to explain them is this thing is how kernel handling the memory segment. after several hours i am find that this function is leading to file checking it’s .TMP, ~WTR and .LNK, here is the function:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/892/1*m6MG3nPQguToLLddRri5qw.png" /><figcaption>LNK checking</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/679/1*WTyqB1lpiywNfrpv3tIYLg.png" /><figcaption>TMP and ~WNK checker</figcaption></figure><p>from this i want to make a simple conclusion about this rootkit somehow the payload will be loaded as .TMP and it will check the presence of .LNK file with specified size 4171, and this root kit is exploiting the I/O manager to delete the {58763ECF-8AC3–4a5f-9430–1A310CE4BE0A} folder and modify them to be the nest of the payload and after that this rootkit will decide to attach this device or not using the method and by exploring the DriverObject to be specified it will infect the USB Driver modify them so they can insert the dropper and the payload at last this rootkit can make the decision to attach or detach the device, not just that as we can see from the string that showed at</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*URRbXKaji-5kPL8tGws6zA.png" /><figcaption>common file system management</figcaption></figure><p>i don’t know but as you can see if Stuxnet is really attacking windows then NTFS and fastfat are make sense for me, i am just having an headache when i thinks about what cdfs doing at there, from my research cdfs it’s used for virtual file system and it provides the access to data and audio tracks for compact disc but it’s usually used for Unix-type operating system, so what cdfs are doing here in my temporary conclusion it’s used for detecting the CD process and it will just read if that device is compact disc or not, please correct me if i am wrong about this one, but seriously in my opinion i think it will be just an compact disc identifier. with this string we can making an assumption about this malware will affect something inside the file system area.</p><h4>counter measure</h4><p>in my opinion, i think if this is the case then we can detect the anomaly activity inside the driver and modified section in IRP overlay and perform the full scan of directory once more after infector is running, it will as simple as after we detach an USB device we could scan the directory one more time to checking the integrity and we can try to make an file scanner that will detect if this file is performing a checker for .LNK file at size 4171 then we can assume that as an root kit that belonged to Stuxnet.</p><h3>Simple anti virus detection technique</h3><blockquote><strong>are you curious about how the anti-virus exactly work?</strong></blockquote><blockquote>take notes that I am just explaining the most simple way to do it is when you are doing a full scan on your computer and then your antivirus gives you a notice if there is some malicious file, sure the exact way is after malware expert finished their analysis about that malware they will judge the appearance using some unique pattern that will show if it’s that malware.</blockquote><blockquote><strong>example</strong>: if I want to create a backdoor and I will use the reverse shell to create a network tunnel to victim computer, what kind of pattern that you will define?, simple if we are want to categorize the reverse shell pattern first is there will be a socket activity and if it’s the reverse shell it will spawn CLI/command line/cmd the easiest way to do it is using system(“/bin/bash”) or you can use execve() or you can using syscall to spawn the command line, you can analyze it and take them as a various pattern that will show if attacker using it as payload, well after we have this pattern we need to upload it to our database and then voila if anti-virus scan file and find this thing they will declare it as a malicious file. I want to show you the most simple way to do it, you can use this as the base logic, first I have a simple ELF executable file all I do is I want to find some various string and decide it if it’s a virus or not. first we have this simple C program and compile it to ELF.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/785/1*aKkHPAV4MtnDIZnvChNkqQ.png" /><figcaption>our C program</figcaption></figure><blockquote>and after you compile it we will decide if it’s virus using 3 string, first is <em>hello</em> <em>world</em>, second is <em>libc </em>and third is <em>gnu, </em>imagine that if we have this database to decide if this is a malicious file, well it’s simple here is my python script to decide it:</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/823/1*lvRM3rzwM6KQGEp1awtwhg.png" /><figcaption>script python</figcaption></figure><blockquote>you can implement this on every file, the logic is simple you have the pattern and you read the file as byte to find the printable string inside the file and you just need to declare if it’s a virus if your count is more than some that you declare, but this technique just takes a benefit of the string matching and the most simple way to do it.</blockquote><h3><strong>resource :</strong></h3><ol><li>Honig, Andrew; Sikorski, Michael (February 2012). <a href="https://www.safaribooksonline.com/library/view/practical-malware-analysis/9781593272906/"><em>Practical Malware Analysis</em></a><em>.</em></li><li><a href="https://web.archive.org/web/20160418151823/http://www.ijarcsse.com/docs/papers/Volume_3/4_April2013/V3I4-0371.pdf">“International Journal of Advanced Research in Malware Analysis”</a> (PDF). ijarcsse.</li><li><a href="https://www.blackhat.com/presentations/bh-dc-07/Kendall_McMillan/Presentation/bh-dc-07-Kendall_McMillan.pdf">https://www.blackhat.com/presentations/bh-dc-07/Kendall_McMillan/Presentation/bh-dc-07-Kendall_McMillan.pdf</a>.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6737e895e118" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ADB root works but ADB remount not works troubleshot(Google pixel 2)]]></title>
            <link>https://medium.com/@tornadohenky1/adb-root-works-but-adb-remount-not-works-troubleshot-google-pixel-2-75a649fd9c15?source=rss-c50b97cf5cb9------2</link>
            <guid isPermaLink="false">https://medium.com/p/75a649fd9c15</guid>
            <category><![CDATA[google-pixel-2]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[mount]]></category>
            <category><![CDATA[adb]]></category>
            <dc:creator><![CDATA[b33f_k4r4g3#kazuya]]></dc:creator>
            <pubDate>Tue, 05 May 2020 14:29:22 GMT</pubDate>
            <atom:updated>2020-05-05T14:30:34.107Z</atom:updated>
            <content:encoded><![CDATA[<p>so i got this problem from several days ago, when i am using adb root it success but the adb remount are not success because somehow we don’t have a root access inside the device and it will looks like the picture below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/573/1*sZ0B6XDbkl1leDun0_Y2dQ.png" /><figcaption>the problem will looks like this.</figcaption></figure><p>&gt;_&lt; annoying, very annoying i am tried it in the third time but the result is still the same, after restart my devices and restart the adb the error still the same, how can that be &gt;_&lt;, so after research the several website i got the explanation about the adb remount, you can use remount command inside the shell and it will looks like “<em>mount -o rw,remount /system” </em>the result are same with adb remount, i got the nice explanation about it from :</p><p><a href="https://android.stackexchange.com/questions/52443/the-command-adb-root-works-but-adb-remount-results-in-operation-not-permit">https://android.stackexchange.com/questions/52443/the-command-adb-root-works-but-adb-remount-results-in-operation-not-permit</a></p><p>but the next problem it’s here, when i try to run the command somehow it crash and says something like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*ps5qv3i61Px4orGPN-88Hw.png" /></figure><p>so after research again what kind of problem in this picture, i am trying to run the mount command to see if the /system is attached or not, but the result is</p><blockquote>1|walleye:/ $ mount<br>/dev/root on / type ext4 (ro,seclabel,relatime,block_validity,delalloc,barrier,user_xattr)<br>tmpfs on /sbin type tmpfs (rw,seclabel,relatime,size=1851264k,nr_inodes=462816,mode=755)<br>/sbin/.magisk/block/persist on /sbin/.magisk/mirror/persist type ext4 (rw,seclabel,relatime,data=ordered)<br>/sbin/.magisk/block/system_root on /sbin/.magisk/mirror/system_root type ext4 (ro,seclabel,relatime,block_validity,delalloc,barrier,user_xattr)<br>/sbin/.magisk/block/system_root on /sbin/charger type ext4 (ro,seclabel,relatime,block_validity,delalloc,barrier,user_xattr)<br>/sbin/.magisk/block/system_root on /sbin/adbd type ext4 (ro,seclabel,relatime,block_validity,delalloc,barrier,user_xattr)<br>tmpfs on /dev type tmpfs (rw,seclabel,nosuid,relatime,size=1851264k,nr_inodes=462816,mode=755)<br>devpts on /dev/pts type devpts (rw,seclabel,relatime,mode=600)<br>proc on /proc type proc (rw,relatime,gid=3009,hidepid=2)<br>sysfs on /sys type sysfs (rw,seclabel,relatime)<br>selinuxfs on /sys/fs/selinux type selinuxfs (rw,relatime)<br>/dev/block/dm-0 on /vendor type ext4 (ro,seclabel,relatime,block_validity,delalloc,barrier,user_xattr)<br>/dev/block/sdd3 on /persist type ext4 (rw,seclabel,nosuid,nodev,noatime,data=ordered)<br>none on /acct type cgroup (rw,relatime,cpuacct)<br>debugfs on /sys/kernel/debug type debugfs (rw,seclabel,relatime)<br>none on /dev/stune type cgroup (rw,relatime,schedtune)<br>tmpfs on /mnt type tmpfs (rw,seclabel,relatime,size=1851264k,nr_inodes=462816,mode=755,gid=1000)<br>none on /config type configfs (rw,relatime)<br>none on /dev/cpuctl type cgroup (rw,relatime,cpu)<br>none on /dev/cpuset type cgroup (rw,relatime,cpuset,noprefix,release_agent=/sbin/cpuset_release_agent)<br>/dev/block/sda7 on /firmware type vfat (ro,context=u:object_r:firmware_file:s0,relatime,uid=1000,gid=1000,fmask=0337,dmask=0227,codepage=437,iocharset=iso8859–1,shortname=lower,errors=remount-ro)<br>tmpfs on /storage type tmpfs (rw,seclabel,relatime,size=1851264k,nr_inodes=462816,mode=755,gid=1000)<br>tracefs on /sys/kernel/debug/tracing type tracefs (rw,seclabel,relatime)<br>/dev/block/sda45 on /data type ext4 (rw,seclabel,nosuid,nodev,noatime,noauto_da_alloc,errors=panic,stripe=4096,data=ordered)<br>/sbin/.magisk/block/vendor on /sbin/.magisk/mirror/vendor type ext4 (ro,seclabel,relatime,block_validity,delalloc,barrier,user_xattr)<br>/sbin/.magisk/block/data on /sbin/.magisk/mirror/data type ext4 (rw,seclabel,relatime,noauto_da_alloc,errors=panic,stripe=4096,data=ordered)<br>/sbin/.magisk/block/data on /sbin/.magisk/modules type ext4 (rw,seclabel,relatime,noauto_da_alloc,errors=panic,stripe=4096,data=ordered)<br>adb on /dev/usb-ffs/adb type functionfs (rw,relatime)<br>mtp on /dev/usb-ffs/mtp type functionfs (rw,relatime)<br>/data/media on /mnt/runtime/default/emulated type sdcardfs (rw,nosuid,nodev,noexec,noatime,fsuid=1023,fsgid=1023,gid=1015,multiuser,mask=6)<br>/data/media on /storage/emulated type sdcardfs (rw,nosuid,nodev,noexec,noatime,fsuid=1023,fsgid=1023,gid=1015,multiuser,mask=6)<br>/data/media on /mnt/runtime/read/emulated type sdcardfs (rw,nosuid,nodev,noexec,noatime,fsuid=1023,fsgid=1023,gid=9997,multiuser,mask=23)<br>/data/media on /mnt/runtime/write/emulated type sdcardfs (rw,nosuid,nodev,noexec,noatime,fsuid=1023,fsgid=1023,gid=9997,multiuser,mask=7)<br>pstore on /sys/fs/pstore type pstore (rw,seclabel,relatime)<br>walleye:/ $ mount | grep /system<br>/sbin/.magisk/block/system_root on /sbin/.magisk/mirror/system_root type ext4 (ro,seclabel,relatime,block_validity,delalloc,barrier,user_xattr)<br>/sbin/.magisk/block/system_root on /sbin/charger type ext4 (ro,seclabel,relatime,block_validity,delalloc,barrier,user_xattr)<br>/sbin/.magisk/block/system_root on /sbin/adbd type ext4 (ro,seclabel,relatime,block_validity,delalloc,barrier,user_xattr)</blockquote><p>i don’t find the /system, after that i was thinking how about i bind the /system well if you want to read some here is the concept:</p><p><a href="https://unix.stackexchange.com/questions/198590/what-is-a-bind-mount">What is a bind mount?</a></p><p>to keep it simple somehow if you are using bind mount it will create the alternate view of the directory tree, and a bind mount it’s not trying to create a different view from the location, but it try to create the reflective of the directory tree or to keep it simple it will make an reflection of the directory tree and everythings that will happen inside the replica will be happen in the original side too, to keep it more than simple we can said it’s an ehmmm mirror of your directory tree, to use it we can:</p><blockquote>mount — — bind /some/where /else/where</blockquote><blockquote>and in our case we are just need to</blockquote><blockquote><em>mount — — bind /system /system</em></blockquote><p>and after that try to use mount -o rw,remount /system and voila your /system directory tree is know mounted to rw access and we can write, push or pull the file inside /system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/460/1*N8uy0lAnv-MSslP5DMawgg.png" /><figcaption>solved</figcaption></figure><p>don’t forget to run it using root access. just type the “su” first, and i am creating this solution on the google pixel 2, hope this will work for you :D</p><p>please let me know if you have the other solution or somehow if i have an mistake at my explanation please let me know :), thank you for read this article :D</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=75a649fd9c15" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[picoCTF[Reverse Me — 300] & a little explanation about linux executable]]></title>
            <link>https://medium.com/@tornadohenky1/picoctf-reverse-me-300-a-little-explanation-about-linux-executable-2069b799b70d?source=rss-c50b97cf5cb9------2</link>
            <guid isPermaLink="false">https://medium.com/p/2069b799b70d</guid>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[b33f_k4r4g3#kazuya]]></dc:creator>
            <pubDate>Wed, 06 Nov 2019 17:55:38 GMT</pubDate>
            <atom:updated>2019-11-06T17:55:38.502Z</atom:updated>
            <content:encoded><![CDATA[<h3>picoCTF[Reverse Me — 300] &amp; a little explanation about linux executable</h3><p>hello guys so today i am just wanted to make some write about CTF, so today i want to create write about how to solve reverse Me with 300 point so in this reverse category all you need to do is knowing what the program actually do for processing some string or some logic, in this problem you will be given 2 files there is .txt file that you need to reverse the string(make a decryptor for the cipher text) so in this reverse me problem, you will be given .txt and the binary, first let’s see about .txt when you open it it will show:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/355/1*6s5JNE6DYg7bym2HiWqd1A.png" /><figcaption>the string that you need to encrypt</figcaption></figure><p>so to get the flag all you need to do is analyse the problem how can they change this string how will this program process it and how can they make something like that, how can they manage the output like that, and don’t forget the second file is the program to make this string basically is an <em>ELF (or to make it simple linux executable), </em>let’s start the reversing things first you can check what is this file using <em>file </em>command in linux.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*25szIfVPheUc71MYpgnkUw.png" /><figcaption><strong><em>file</em></strong></figcaption></figure><p>in this command file we can find the true information about the file, from this command we can know if this file is an elf with 64 bit version, x86–64 version 1 (SYSV), not stripped, what is this today i just want to explain some about linux binary so we can see in this picture let me explain for you partially:</p><h3>Header File</h3><p>so in here we can see if the header file is ELF but if you are ever hear something about magic number ELF have it too you can use one tools in linux it’s called <em>readelf</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/705/1*RTczaQOfjy6n4bOQgGXpWw.png" /></figure><blockquote>you can use it just by typing <strong><em>readelf -h filename</em></strong>, but in here you need to focus for the header 7F 45 4C 46 02 01 01 00 00 00</blockquote><p>this is the header of the ELF file each one of them have their definition, 45=E, 4c=L, 46=f and prefixed with 7F, after that 02 it’s mean the class if 02 then it’s 64-bit but if it’s 01 it will be 32-bit, next is the first 01 it will explain something about the byte order is it LSB(Least Significant Byte) or MSB(Most Significant Byte) if 02 then it’s MSB, after this it’s 01 again but it’s just explain about the version of this ELF currently we are using the version 1 so nothing interesting to remember from this section</p><p>after that let us see about what is ABI ? ABI Version ? this section will explain about SYSV</p><h3>ABI(Application Binary Interface)</h3><p>each operating system have their own common list of similiar function, in addition they need to specify ones or at least minor differences between them, and in this section they are all are described and translated into something and already set in ABI(Application Binary Interface), in this way operating system and application both now what to expect and function are correctly forwarded, these 2 fields are described version of the ABI and the SYSV, what is SYSV, is called UNIX System V is one of commercial version of UNIX operating system, so in this section we will know if the output will be shown as System V.</p><p>next is type:</p><p>there is a lot of type that will explain about what will that file work there is 4 in the common list of file:</p><ul><li>CORE (value 4)</li><li>DYN (Shared object file), for libraries (value 3)</li><li>EXEC (Executable file), for binaries (value 2)</li><li>REL (Relocatable file), before linked into an executable file (value 1)</li></ul><p>well after this i want to explain about program section but in a row of general knowledge you need to know first in a program there is 3 common section :</p><ol><li>Program Headers</li><li>Section Headers</li><li>data</li></ol><p>next is i want to tell you about how to solve the picoCTF challenge first you need to analyse the program, i am using IDAPro v7.0 to reverse it and disass it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1022/1*VSbKQ2LQ1btFqJKOkh0k8A.png" /><figcaption>IDAPro output</figcaption></figure><p>first that all you need to know that IDAPro can make an pseudocode that will be looks like C but i will not recomend this because if you are read assembely you will know the algortihm more fast then you are seeing the syntax in pseudocode</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PEfkNvRe5KjaEjqO3F6rXw.png" /><figcaption>picture 1</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GpuUfLvhJPfgVOh9nDRoyw.png" /><figcaption>picture 2</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/819/1*0MsRFC_uG-UusN_YasKxNw.png" /><figcaption>picture 3</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1018/1*7lrS8G8WIYXlRB0EjzxDzQ.png" /><figcaption>picture 4</figcaption></figure><p>huh it’s sucks and make your head dizzy right but if you aren’t like to read them from raw assembly you can prefer to read them in pseudo code but it will affect you when you are want to do the patching technique to make sure you can do that you must now what kind of instruction in assembly that you want to patch to the program.</p><p>first let us take sharp look in the conditon of the string, you will find it at what this program do first this program is reading some file from picture one and this instruction</p><blockquote>push rbp<br>mov rbp, rsp<br>sub rsp, 50h<br>lea rsi, modes ; “r”<br>lea rdi, filename ; “flag.txt”<br>call _fopen<br>mov [rbp+stream], rax<br>lea rsi, aA ; “a”<br>lea rdi, aRevThis ; “rev_this”<br>call _fopen<br>mov [rbp+var_20], rax<br>cmp [rbp+stream], 0<br>jnz short loc_11CE</blockquote><p>with reading this instruction you will know if this program is reading the file from flag.txt and then they will append something to rev_this file and after that they will compare the stream, while stream it self it’s the function that open flag.txt they will said if you are doesn’t have them then they will refered to picture 2, it will “No flag found, please make sure this is run on the server” and if they are found the rev_this this program will just make an output “please run this on the server”.</p><p>next thing is we know this program is using the .txt file as a temper to write something that they process in this program but second thing is you need to know about how the algorithm is developed in here, if it’s something like that you can see the picture 4 process they have</p><blockquote>loc_124C:<br>mov eax, [rbp+var_C]<br>cdqe<br>movzx eax, [rbp+rax+ptr]<br>mov [rbp+var_1], al<br>mov eax, [rbp+var_C]<br>and eax, 1<br>test eax, eax<br>jnz short loc_126F</blockquote><p>in here they need to do create a looping to process the string after that they will compare the the eax with 1 they will test if the eax will be 0 or not zero if they are not zero then they will jump to <strong><em>short loc_126f.</em></strong></p><blockquote>loc_126F:<br>movzx eax, [rbp+var_1]<br>sub eax, 2<br>mov [rbp+var_1], al</blockquote><p>they will jump into here if the condition are meet. in this part we can find if they will have somekind of string they will sub it with 2, you can also translate into eax[i] = eax[i]-2. if they doesn’t meet the conditon to jump they will go to the next line after the special jump instruction this is really tricky but this is the natural of assembly.</p><blockquote>movzx eax, [rbp+var_1]<br>add eax, 5<br>mov [rbp+var_1], al<br>jmp short loc_1279</blockquote><p>if they are going to this line then the process will be diffrent from that condition of jump it will add the string with 5, the assumption is</p><blockquote>if(eax &amp; 1){</blockquote><blockquote>somechar -= 2</blockquote><blockquote>}else{</blockquote><blockquote>somechar += 5</blockquote><blockquote>}</blockquote><p>if you are already get what i mean then the next step is we are just need to create an program to process the string that we need to solve.</p><p>here is my program</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*G8J7cvjJ7zZomAfH1iDlJg.png" /></figure><p>i am using python here and make some contracdiction logic from the real logic so we can get the string</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/554/1*latN14hfstligwwQUj3MFg.png" /></figure><p>after you are run the script then the output will be looks like this picture</p><p>so the answer of this challenge is picoCTF{r3v3rs32ccdd282}</p><p>so that’s it for today, thanks for taking your time to read this article, please let me know if there are a wrong explanantion in here and well sorry because i am not good in english.</p><p>resource:<br><a href="https://linux-audit.com/elf-binaries-on-linux-understanding-and-analysis/">https://linux-audit.com/elf-binaries-on-linux-understanding-and-analysis/</a></p><ul><li><a href="https://askubuntu.com/questions/690631/executables-vs-shared-objects">Executables vs Shared objects</a></li><li><a href="https://askubuntu.com/questions/690631/executables-vs-shared-objects">Executables vs Shared objects</a></li></ul><p><a href="https://reverseengineering.stackexchange.com/questions/3815/reversing-elf-64-bit-lsb-executable-x86-64-gdb">https://reverseengineering.stackexchange.com/questions/3815/reversing-elf-64-bit-lsb-executable-x86-64-gdb</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2069b799b70d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Starting some hot introduction with frida part III with ARM]]></title>
            <link>https://medium.com/@tornadohenky1/starting-some-hot-introduction-with-frida-part-iii-with-arm-1ccf1af910ba?source=rss-c50b97cf5cb9------2</link>
            <guid isPermaLink="false">https://medium.com/p/1ccf1af910ba</guid>
            <dc:creator><![CDATA[b33f_k4r4g3#kazuya]]></dc:creator>
            <pubDate>Wed, 28 Aug 2019 10:37:51 GMT</pubDate>
            <atom:updated>2019-09-23T16:11:58.686Z</atom:updated>
            <content:encoded><![CDATA[<p>in the first time of my life after i am doing reverse engineering 2 years, all i am just learning is assembely with 32 bit mode but when i am trying some andorid testing and learning about frida i am starting to learn about ARM-v6 with ARM family ARM11, so first let’s talk about what the different between intel processor and ARM processor. there is a little diffrent between them just like intel are using CISC(Complex Instruction Set Computing) and ARM is using RISC(Reduction Instruction Set Computing), the diffrent is when we starting a topic about CISC in intel processor we can see that CISC processor has a larger registers and more feature-rich instruction set and allow many complex instruction to access memory, it has many operation but they doesn’t have so many register just like ARM, it therefore has more operation and addressing mode, CISC mainly are used in PC, workstation and server, RISC the diffrent is RISC has more register to process them, RISC processor has a simplified instruction set(100 instruction or less) and has so many general purpose unlike intel they have a lot more register to process them, unlike CISC RISC is using their register to process load and store to memory, so in theory of RISC they have 3 types of instruction(load, store and increment) it’s possible for RISC doing execution more faster than CISC, but because of RISC doesn’t have a lot of operation that’s make a lot of efficieny in writing code for doing some software development using ARM. let’s talk about how we can develop ARM, first all you need to do is just like when you write the assembely code all you need to do is just write your code and save it using .s extension in assembely we are just using .asm you can use NASM for compiling the assembly language with</p><p>“nasm -f elf &lt;name of file&gt;.asm”</p><p>after that we will have .o output and then the lasting that we will do is just create the elf mode in the linux using ld</p><p>“ld -m elf_i386 -s -o &lt;your file&gt;.o execute_name”</p><p>and you can just execute them using “./”</p><p>if you are in ARM we can use “as” and “ld” too, but the diffrent is processor we can’t code the RISC processor in CISC because of RISC have a lot more of register and the output is the same we are just using as to create .o output and then we can create executable file just using ld</p><p>“as program.s -o program.o”</p><p>after that we will have program.o and then we can create the executable files using “ld”</p><p>“ld program.o -o program”</p><p>let’s talk about ARM theory because i don’t have RISC processor :(, let’s see about data type and register first, ARM can process some data type just like they can store word, half words and bytes but ARM is just doing some load and store processing they can store/load unsigned data and signed data, ARM have a lot of extension for their data type just like</p><p>extension:</p><p>-h/-sh is an extension for halfwords</p><p>-b/-sb is an extension for bytes</p><p>but word doesn’t extension because word is having a size of 32 bit of pieces or max size of operation so ARM make it default for their instruction to load 32-bit if you aren’t define it. signed vs unsigned it’s just signed can hold both of positive and negative bytes of data type but unsigned can just hold the byte positive or after 0.</p><p>there is a lot of syntax that ARM have but we need to know the most important part in ARM it’s called load and store it’s the main point of instruction in ARM, let’s start so first that we will see is load,</p><p>load operation is copies the from main memory into register, and store operation is copy data from register into main memory(LDR(load)|STR(strore)).</p><p>syntax:</p><p>&lt;load&gt;</p><p>ldr = load word</p><p>ldrh = load unsigned halfword</p><p>ldrsh = load signed halfword</p><p>ldrb = load unsigned byte</p><p>ldrsb = load signed byte</p><p>&lt;store&gt;</p><p>str = store word</p><p>strh = store unsigned halfword</p><p>strsh = store signed halfword</p><p>strb = store unsigned byte</p><p>strsb = store signed byte</p><p>and then let’s talk about byte order, so first let me tell you that ARM is using little endian before version 3, after that ARM is using the BI-endian but because they create the feature that setting which allow for switching endian, they became <em>endianess.</em></p><p>Endian is how our computer read the byte, usually they called it byte order.</p><ol><li>little-endian(least-significant byte)</li><li>big-endian(most-significant byte)</li></ol><p>big endian is stored first(at the lowest storage address) and little endian is stored first.</p><p>Register, in ARM they have a lot more register than assembly, there are 30 general purpose in 32 bit register, but ARMv6-M and ARMv7-M based processor. the first 16 register is accesible for user level mode, the next register are avaiable in privillege software execution execpt ARMv6-M or ARMv7-M. privillege software have some mode inside them, just like user level mode, system mode, supervisor mode, FIQ, IRQ, undefiened mode, abort mode, monitor mode and hypervisor mode i will explain about it later.</p><p>next so in ARM we can access 16 registers, all of them have their purpose : <br>R0-R6 it’s for general purpose we can use it as temporary to load or to store our data from main memory to register or from register to main memory</p><p>R7 are used to be general but it have their special job just like holds syscall number, R8-R10 is for general purpose too, and here is the register that are used to be a special case just like in assembly we will know about that EAX, EBX, ECX, EDX are for general purpose buat they have their special case too example just like EAX who will act as accumulator in assembly, or ESP, EBP, EIP that are act in area for point the program or create main frame memory for pointer, or ESI and EDI that are have a job to control the source of the string or destination of some string, but in ARM they have the same thing to just like:</p><p>R11 it’s called FP or Frame Pointer that will act as EBP in assembly it’s just looks like that EBP/R10/FP will insialise where the first offset point to start our program or to start some function.</p><p>R12 is called Intra Procedural Call it’s more looks like instruction pointer in assembly, R12 are used to point to next line that we will execute so that program will run looks like procedural, but they will store the adderess.</p><p>R13 is called SP(stack pointer) it’s also called ESP in assembly, stack pointer will be store the size of the memory stack for some function or some data, why it’s not like you inisialise array it will looks like it will be a point to point the top of the stack. in assembly you will see something like</p><p>R14 is called LR(Link Register) link register are created when we are doing some function call routine it will make a link register and do update to the memory address link register make it so if our program will run until anywhere that we are don’t know(subroutine program) it will return back to their link register point so our program will always run as procedural or run as we command or return to their parent function.</p><p>R15 is called PC(Program Counter) program counter will automatically increment when we are execute some instruction, it will increment but it will do as their version ARM state or Thumb state if it ARM state then it will +4 byte for their address but if they are in Thumb state it will + 2 byte, so PC will store their current address instruction and it will looks like if the our current memory is 0x100000F then 0x100000f will be added with 8 and if the program is running in Thumb state then it will added with 4.</p><p>CSPR(Current Program Status Register) is looks like a flag in the assembly.</p><p>ARM have a lot of flag and some unique flag that CISP function it’s to make condition in current program status.</p><p>N = negatived it will enable if the result is negative</p><p>Z = Zero it willl enable if the result is zero</p><p>C = Carry it will enable if the value it’s needed 33rd bit for execute</p><p>V = Overflow it will enable if the value can’t be presentate as 32 bit</p><p>E = endian-bit you can use this flag to define their byte order if 1 for big endian and 0 for little endian</p><p>Q = Underflow</p><p>J = Jazelle this flag is used to give access to ARM processor to execute java byte code</p><p>GE = greater than or equal for SIMD</p><p>A = abort disable</p><p>I = IRQ disable</p><p>F = FIQ disable</p><p>T = Thumb it’s somekind of flag that define if we are in thumb state but it will disable if we are in ARM state</p><p>M = processor mode(privillege mode)</p><p>Example 1 :</p><p>writing an program to make an syscall to call a shell.</p><p>so in C:</p><p>we will create somecode that’s looks like</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/1*kcfoRIoCETffTy02o7HG2g.png" /></figure><p>ARM:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/303/1*VLGkZ6AN2Z3t5VR6fkH2CQ.png" /></figure><p>so in this ARM code we perform syscall that will go to execv and then they will call shell “/bin/sh”</p><p>r0 -&gt; “/bin/sh”</p><p>r1 -&gt; 0</p><p>r2 -&gt; 0</p><p>r7 -&gt; 11(R7 will hold syscall)</p><p>and then we execute it and them using svc</p><p><a href="http://shell-storm.org/shellcode/files/syscalls.html">System Call Table</a></p><p>you can see more in here, so we can use execv to spawn shell.</p><p>the syntax will looks like execv(“/bin/sh”, argv, envp), and they are using syscall 11.</p><p>example 2:</p><p>reverse shell TCP, so first that we can create a bind shell using C but we can implementate it in ARM this is quiet easy because we are just translate it into ARM and perform syscall to do the socket or something like that, so first code C</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/954/1*CLSB6v6vh7Pdn45oGnlo2A.png" /></figure><p>ARM:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/462/1*FvbGFHyx3hgaQD89Kjh39w.png" /></figure><p>resource:</p><p>book:</p><ol><li>Practical Reverse Engineering: x86, x64, ARM, Windows Kernel, Reversing Tools, and Obfuscation by Bruce Dang, Alexandre Gazet, Elias Bachaalany and Sebastien Josse.</li><li>Guide to Assembly Language Programming in Linux [Dandamudi 2005–07–15]</li></ol><p>web:</p><ul><li><a href="https://developer.arm.com/docs/dui0473/k/writing-arm-assembly-language">ARM Compiler armasm User Guide Version 5.05 | Writing ARM Assembly Language - Arm Developer</a></li><li><a href="http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dai0179b/ar01s02s07.html">ARM Information Center</a></li><li><a href="http://shell-storm.org/shellcode/files/syscalls.html">System Call Table</a></li><li><a href="https://azeria-labs.com/writing-arm-assembly-part-1/">Writing ARM Assembly (Part 1)</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1ccf1af910ba" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[starting some hot introduction with Frida: part II]]></title>
            <link>https://medium.com/@tornadohenky1/starting-some-hot-introduction-with-frida-part-ii-a5cd93ec2403?source=rss-c50b97cf5cb9------2</link>
            <guid isPermaLink="false">https://medium.com/p/a5cd93ec2403</guid>
            <category><![CDATA[frida]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[b33f_k4r4g3#kazuya]]></dc:creator>
            <pubDate>Fri, 26 Jul 2019 06:42:53 GMT</pubDate>
            <atom:updated>2019-09-14T07:01:02.596Z</atom:updated>
            <content:encoded><![CDATA[<p>hello again, welcome back to my story with my new girlfriend Frida, but today i want tell all of you again, that she is so sexy, why ?, because when i am trying to learn something i found something more interesting in Frida, so we can do some dynamic analysis in Frida just by using frida-server and attach your frida-server in your android, so the logic is we install and run the frida-server in our android and then when we try to do some trace or doing some debugging activity we can do that in our device, it’s cool right, yeah dawn Frida is really cool with such a function, we can see that as a client-server concept.</p><p>but first all we need to do is download the Frida-server at <a href="https://github.com/frida/frida/releases/tag/12.6.11">https://github.com/frida/frida/releases/tag/12.6.11</a>, and then download frida-server but don’t forget to syncronise the version of your architecture it will be 64-bit or 32-bit, mine is 64 so i download 64 version of frida-server, and then after that we need to make sure we are going to root our phone first, and then we need to download adb you can find it here <a href="https://developer.android.com/studio/command-line/adb?gclid=CjwKCAjwpuXpBRAAEiwAyRRPgZ7k_I-yy9Sp3wgW2Q8dEMd-WusUamwOdlPZ85tAEoP1uMprBXfjyxoCRGkQAvD_BwE">https://developer.android.com/studio/command-line/adb?gclid=CjwKCAjwpuXpBRAAEiwAyRRPgZ7k_I-yy9Sp3wgW2Q8dEMd-WusUamwOdlPZ85tAEoP1uMprBXfjyxoCRGkQAvD_BwE</a>, and then finally all we need to do is push our frida-server to our device with adb.</p><ol><li>remember to enable USB-debugging in your developer mode, and then check are your devices connected with adb or not by using “./adb devices”- macOS, sometimes when we are making new connection between our devices and adb, there is somekind of error like when you check the list it said your devices is unauthorized, or your device not avaiable it’s okay by the way because when you get not avaiable you are just need to restart the adb server and don’t forget to kill the process first, but when you get unauthorized the simple think is if it’s your first time then you are just need to press ok, when some pop up show in your phone with some of weird mac address, but if you already connected and it’s show unauthorized then you are need to delete adb key in your adb file in your device and then kill adb server restart it and do the same thing again.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/525/1*ZHo4H0l-nDoqyFNlRFMf-g.png" /></figure><p>2. after that you need to use this command, first we are going to need to push your frida-server to the device, using “./adb push frida-server /data/local/tmp/”, after that don’t forget to change the permission of frida-server to executable, you will use “./adb shell”, first and go to you frida-server location after that you need to use “chmod 755 frida-server”, after that all we need to do it’s just to execute frida-server, with ./frida-server, if you are have an error looks like your address is already used or something like that, all you need to do it’s cut/kill the frida-server first and start it again, you can use “ps”, and then “kill (pid(frida-server))”.</p><p>3. last if we want to see is our frida-server is okay then we can use one of frida tools to test that, we can type on our device frida-ps -U then frida will generate all the process is running on our android.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*WScCFqD2bSJ0aeruKzpsCA.png" /></figure><p>nah so in this journal, i want to show you something cool that we can do to support our static analysis using frida, so i have apps called “root checker”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w6fbd7emtZUQ5diCbuOOVA.png" /></figure><p>so if you already rooting your device with TWRP custom recovery and installed magisk or SUapp, you can test if your device are already root or not by using one of application that you can download from playstore it’s called root checker by joeykrim, so first think first we need to get .apk first because my device already have a root access all i need to do it’s going to app folder and create backup from it after that we can transfer the apk to our device to starting our static analysis.</p><p>first i will show you some tool that we need to have for doing this assesment , we need to have dex2jar, apktool, ghidra and jadx-gui, but if you don’t want to install so many tools like dex2jar, apktool and jadx-gui, you can use JEB decompiler instead of installing so many tools. before doing this static analysis, first you can use apktool to extract .apk to get their source like .xml or their configuration but remember when you extract it using apktool you can’t have .class or some .java all you have it’s .smali, what is that ?, smali is similar to assembly language, so why we need to convert java source code to .smali, the procedure is when we are going to compile our java in eclipse or something like java compiler, they are converting our java source code to .dex(dalvik executables) just like when we are creating our C program we are going to write source code first and then compile it using gcc the same thing is if we are going to decompile this executable files, all we can get is not their source code but all we can get is assembly but with some help of powerfull tools IDAPro we can get some pseudocode looking like C, if we are using linux or macOS, we will get an ELF-file or executable file to run our program it’s the same thing with java, more detail our android have dalvikvm(dalvik virtual machine) so our android can run .dex files, in order to having a universal language to make our machine easy to understand our code they create smali, like i said smali is have some similar to asm, what diffrent let me show you something.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/547/1*m2MiLk1N8-jrDCD389CovQ.png" /><figcaption>assembly</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/445/1*2DZULA7ow5oqAJpaOL1QxQ.png" /><figcaption>smali</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/469/1*onAWN130EQKFFUyN_QJf6w.png" /></figure><p>yeah, somehow i think assembly more easy to read, maybe because i learn to read asm first than smali, next i have a simple move in here if we are using apktool first we need to translate .smali to .jar if you want to read them as java using jadx-gui, but we can use some cheat, so first all you need to do is using dex2jar and make your .apk to .jar using “d2j-dex2jar file.apk”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/565/1*BXP7oInPWqiYMlhoj4HENQ.png" /></figure><p>after that open your .jar in your jadx-gui.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/956/1*yBlFdiNqVpF1ZNYSoAgtmA.png" /></figure><p>nah i found something intersting here so their algorithm is by checking in /system/app/Superuser.apk, they are going to check this if the file is avaiable then this function will return true, but before i get in here i am trying to see how the apps can do the checking so first i am trying check with frida-trace how can this apps check root, nah first i am using “frida-trace -U -i open com.joeykrim.rootcheck” after that you will see the output, but first run app in your android and then, you will see stand by output just like</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/568/1*_0C36Y3jgU7jrKwdVz-XmA.png" /></figure><p>frida-trace is tracing our the app, open() calls, well i find something in here when i press the verfiy root button this apps is open(/proc/self/fd), so i assume this apps it’s trying to get the current process of our android.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/367/1*rJ619FWjX9XDkBR9Dkn5mA.png" /></figure><p>and then next step is i am trying to figure out how about i am starting to search all the code segment that have some “/proc” operation and i find something cool</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*fSJC59ZWL2mnlrLPlIBKGA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/666/1*Q8ZnUewBNK1OPLCCDhH0fQ.png" /></figure><p>so if you have “/system/app/Superuser.apk” file and it exists then the validation will return true first and then they will return !z and checking some “/system/xbin/su” if they are exist then the return will be construct just like 1 &amp;0 or 1&amp;1 something like that , this is what i said about frida is really helping you out even when you do some activity like static analysis, next what happen is we can inject it using frida and change the return value so we can assume the rootchecker will said it’s not root, but when i am trying to look again in my frida-trace i found something interesting again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/442/1*LVN6OtQpmaufl3AoTm-b9Q.png" /></figure><p>it happen when i am touch the verify root in root checker apps, so i am starting to ask our big master google, and found some good article about kernel exploitation.</p><p><a href="http://powerofcommunity.net/poc2016/x82.pdf">http://powerofcommunity.net/poc2016/x82.pdf</a>.</p><p>and it’s really cool, learning some how can someone actually using leaked sock address from “/proc/net/xt_qtaguid/ctrl” and then recreate some fake address and fake structur or modified FPT(proto_ops) area.</p><p>but if you using JEB decompiler you can find class called “ceu” maybe it’s contain asyncronous task that running the validation for checking some SUapps, or magisk in the directory,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/351/1*7k3zNkPJwV0J9C8U8NYueg.png" /><figcaption>Using JEB decompiler</figcaption></figure><p>it looks like they are trying to find is there any root management apps in our android, after that i find something in this apps too, they are trying to access their privillege in our android. checking the permission of that file and then execute some shell too.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/587/1*cu-k-zSo5BpHfPfnw8-4zg.png" /></figure><p>in this journal i hope i can try to show you how to bypass the rootchecker when you are trying to access some application but you can’t access it because you are already root your phone, so i am trying to search some alternative but have the same way to solve it. let’s get to the topic now, first all you need to search is owasp crackme or uncrackable they have some simple root detection and antidebugger too, you can download it here :</p><p>“<a href="https://github.com/OWASP/owasp-mstg/tree/master/Crackmes">https://github.com/OWASP/owasp-mstg/tree/master/Crackmes</a>”.</p><p>then all you need to do it’s install the app using “./adb install UnCrackable-Level1.apk”, after installing it you will find a normal application and then they are just going to display some message about that your device have a root access and you can’t continue access it further more.</p><p>because of there are multiple validation of the root checker and anti debugger. so first time let me show you something because static analysis is the most important part in here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/382/1*aMBVddhBC4Kc8yYH0Xge6Q.png" /></figure><p>and then if you already see the sg.vantagepoint.a.c you will find 3 rootchecker, first is module a() they are trying to find su, is exist or not in the directory, and at b() they are trying to find “test-key” in a file so you can see if there is any file that contain rooted device pattern and last is c()</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/1*Kq6bicXmZ__AYOAlgE9EKA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*mlV-8gjIk6dAAjZG0wFuLw.png" /></figure><p>they are trying to find if there is contains such application that will help you to manage the root, just like root management or something like root panel so in here you can see there are 3 validation in here, and if we see more we can find something more</p><p>so second thing is we found something that looking like an application status or yeah somehow is trying to check if your application is in debug mode or not and it using one of flag from java, i don’t know how to explain it, but let’s call it simple anti debugger</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/491/1*cz-WeHhMB2uu8EvCN3u8TQ.png" /></figure><p>and then the last thing is interesting about this .apk is their mainActivity</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/388/1*-D2gpYNGutM71PVr8LnI3g.png" /></figure><p>so when you are lunch the application there are actually it’s not the root detection that make you out from the application but it’s their “ok”, button is already set to make you exit if you press it LOL.</p><p>think it first if we are using “frida-ps -U” to analyse the process of the .apk, there is no sign of the .apk we can’t find it, but if we are checking our “./adb logcat” we can find some trace of that process just like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/565/1*uNuyaNvePbCrLQrSK1KbCA.png" /></figure><p>the reason the program looks like it because it’s not running in the first time it’s just run to create a pop-up like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EYyC5Vnx6EAvN9R9IuaI0w.png" /></figure><p>and next i am trying to disable the program exit first, using javascript that will be created as payload for frida.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/466/1*nWAnW-QHDBlLdqQiPptJaA.png" /></figure><p>in some file called frida.js, let me explain this line of code first so first is we are going to perform an function that will executed, in the first line we are going to use java.Perform() to attach our modified function to current thread, and then next we are going to send some string so we are now where are our code going to start, and next is the most important sequence it’s the payload that we are using so we can disable the exit first just like the other we are going to overload the function and using function(v) to make the program not exit, and after that to test if our overload is running or not it’s just by using we can send some string again to check if our function is running or not.</p><p>after that we are going to use “frida -U -l frida.js owasp.mstg.uncrackable1”</p><p>and then you can go inside the application without having some exit first.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A55y5taEQ2jvE6ckl-GeJA.png" /></figure><p>after that we are going to talk about how we can disable the root checker, but first all we need to do it’s just make all rootchecker thing return 0;,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/232/1*T1eQg7Ir4v8RcFA8CYplMA.png" /></figure><p>we are going to remove anti debugger to so let’s code them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*tEB5isrNF4tw5D8Z1lCB7w.png" /></figure><p>to do is define them and then make all the class/method that check the root and check antidebugger is return 0; and then we are just need to run the frida command again and voila you can lunch the apps free without any root detection.</p><p>and last about finding secret inside the program, it’s literally easy to see,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/356/1*CrHkvvAr-I7-kk8zxS_Ung.png" /></figure><p>this is the function to check if your secret is correct or not.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/677/1*p8oF5bSAA4_t9k-9n2QOSQ.png" /></figure><p>this is how they are going to process their character.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/413/1*mo9_nJMHJIgo64qzzEsttA.png" /></figure><p>after that we can all we need to do it’s just open it because we are knowing the algorithm but if you are to lazy to do that thing we can use frida too.</p><p>we can use frida to decrypt the text just by create script that will looks like</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/404/1*FbnJODE99s6V1hGDYpRGDA.png" /></figure><p>if you are using python you will create a simple script that will looks like</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/595/1*h0SOaw5Q5IJ_a4vT3FccQg.png" /></figure><p>after that you need to run the script using frida if you are want to use frida -U -l (name).js owasp.mstg.uncrackable1 or you run the python script just using python (name).py. after you run the script it will give you an output like</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9SDLf1npdIBDbBpF5fpHWA.png" /><figcaption>Frida</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/495/1*n2Pxgn2_BHAEXiwHscy0Rw.png" /><figcaption>pyhton script</figcaption></figure><p>type it and you will find the secret “I want to believe”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yO0DpzeSKZBxcocGvijjeA.png" /></figure><p>so that’s it for this journal, in next journal i will starting to use frida to modify function to bypass some validation, meanwhile i am trying too research about arm aarch86, hooking zygote, and how about if we can patch some snippet of ARM in the .so files and we create them to download something like reverse_tcp payload or something like that, but next i want to research about how fingerprint work in some apps, after that how about we can bypass fingerprint authentication with frida :0.</p><p>thank you for read, sorry for bad english if there is wrong explanation in my journal i hope you will let me know, comment me, thanks for taking your time to read this journal.</p><p>source:</p><ul><li><a href="https://www.frida.re/docs/android/">Android</a></li><li><a href="https://www.quora.com/What-is-smali-in-Android">What is smali in Android?</a></li><li><a href="https://android.stackexchange.com/questions/176083/does-test-keys-mean-device-is-rooted">Does &quot;test-keys&quot; mean device is rooted?</a></li><li><a href="https://developer.android.com/reference/android/content/pm/PackageManager">PackageManager | Android Developers</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a5cd93ec2403" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Starting some hot introduction with frida]]></title>
            <link>https://medium.com/@tornadohenky1/starting-some-hot-introduction-with-frida-3993f00d02a2?source=rss-c50b97cf5cb9------2</link>
            <guid isPermaLink="false">https://medium.com/p/3993f00d02a2</guid>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[b33f_k4r4g3#kazuya]]></dc:creator>
            <pubDate>Thu, 25 Jul 2019 09:17:21 GMT</pubDate>
            <atom:updated>2019-07-25T09:22:15.268Z</atom:updated>
            <content:encoded><![CDATA[<h3>Starting some hot introduction with frida: part 1</h3><p>Frida is so hot, so sexy and so beautiful such a beautfiul tools that you can use to inject something to the android module and frida using python as platform, because frida is using C as basics for create them, frida is created to make some kind of injection to google’s V8 engine, so when we are doing somekind of injection then we are going to use javascript for making the payload of injection, no let’s get serious, frida is dynamic code instruction to do some dynamic analysis in android platform, windows, linux, mac, iOS.</p><p>So first think first we are going to know how to config our sexy girl, yes it’s Frida, first we need to install it first using “pip”</p><p>But first think first don’t forget to make sure that you are using python version 3.X because when i’m trying to install it at my MacOs, there is somekind of error i don’t know but when i am trying to search it at github they said Frida cert was bad, but the topic already disclosed and they said it’s already fixed in the Frida patch. but still i can’t install it hehe, so i am trying to install python3 and get some pip installed using python3 to and then boom, install successful, yeah it take a weeks for me to install that sexy girl.</p><p>now we are going to install frida using pip with command :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/255/1*lpPWIIiiLV5dDDFfoGNVAg.png" /></figure><p>“pip install frida-tools”.</p><p>after it we will trying to test our beautiful girl called Frida, first you can test it by using one of Frida tool is called frida-trace you can try it, if there is no problem when you are installing the frida then your command prompt will looks like.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/645/1*0xlgz23UOlCqaLF9fzX9-w.png" /></figure><p>but remember i am using my outdated mac, and second we can proof that our frida it’s installed by trying to import Frida library in python if your installed Frida doesn’t have any problem it will looks like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/679/1*LhXzpwewQydur0ckVnv-Cg.png" /></figure><p>and then let’s get some introduction to our beautiful girlfriend Frida by trying to hook the library when some of the program are running.</p><p>but first i will create simple program C and execute it and then we are going to make our Frida to hook the library that used while our C program is running, first let’s create some simple code maybe we can create our first time when we are learning about code “hello world” and set some getchar in your program so it will take everything that you input before the program is closing/ end their session, the code will looks like</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/257/1*kA-UIgfD5XZe-sl-M7-Pwg.png" /></figure><p>after that execute your program and run it, but ! don’t close your terminal just let it take some space to idle, after that then we can start to use our simple script with Frida to hook the library the script will looks like.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/492/1*TBSi5OaTZXWLFuI8vhgE2g.png" /></figure><p>this is how our Frida will take that library from the exe program. First let’s take a deep look to our script, to make sure first think first you need to import frida library and then we are going to create one function to print our message, and next we are going to attach our girlfriend to the target/that running process that you want to hook, next we are going to use javascript to make that payload, that we are going to use for hook, but let’s take a look to rpc and enumerateModule, RPC(remote procedure call) is a protocol that one program can use to request the service that located in another computer or another network without having to know about the networks detail, RPC is using client-server model. but in our case we are going to request to our localside computer or you can say we are going to request our service to ourself, while we are talking about RPC, i am learned something called procedure calls is also known like function call or subroutine call, to make it simple for us to understand we are creating client-server service in our local and we are going to request our service to take the information about module, and then we are returning a syncronise Process module that we are need like in our short that going to attach at service called exe and then the javascript will take a syncronise module and then boom we get our result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*xB31OpZ9xVFEb_L2Pt4-kg.png" /></figure><p>this is the output looks like, but first let me explain it so Frida is going to inside the memory and starting looking an running process called “exe” and then execute our payload, so this is how Frida work, is so sexy right, i am falling in love with frida</p><p>that’s it, sorry for bad english and sorry if i using some repetion word or typo, please feel enjoy to read it, if i am having some wrong explanation please let me know, comment me, thank you for taking your time to read my ugly jurnal.</p><p>source:</p><ul><li><a href="https://searchmicroservices.techtarget.com/definition/Remote-Procedure-Call-RPC">What is Remote Procedure Call (RPC)? - Definition from WhatIs.com</a></li><li><a href="https://www.frida.re/docs/home/">Welcome</a></li><li><a href="https://github.com/frida/frida/issues/657">install frida error · Issue #657 · frida/frida</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3993f00d02a2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>