<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>C on TurboVision</title>
    <link>https://turbovision.in6-addr.net/tags/c/</link>
    <description>Recent content in C on TurboVision</description>
    <generator>Hugo</generator>
    <language>en</language>
    <lastBuildDate>Tue, 21 Apr 2026 14:06:12 +0000</lastBuildDate>
    <atom:link href="https://turbovision.in6-addr.net/tags/c/index.xml" rel="self" type="application/rss&#43;xml" />
    
    
    
    <item>
      <title>Format String Attacks Demystified</title>
      <link>https://turbovision.in6-addr.net/hacking/exploits/format-string-attacks/</link>
      <pubDate>Sun, 14 Dec 2025 00:00:00 +0000</pubDate>
      <lastBuildDate>Sun, 22 Feb 2026 15:49:27 +0100</lastBuildDate>
      <guid>https://turbovision.in6-addr.net/hacking/exploits/format-string-attacks/</guid>
      <description>&lt;p&gt;Format string vulnerabilities happen when user-controlled input ends up as the
first argument to &lt;code&gt;printf()&lt;/code&gt;. Instead of printing text, the attacker reads or
writes arbitrary memory.&lt;/p&gt;
&lt;p&gt;We demonstrate reading the stack with &lt;code&gt;%08x&lt;/code&gt; specifiers, then escalate to an
arbitrary write using &lt;code&gt;%n&lt;/code&gt;. The write-what-where primitive turns a seemingly
harmless logging call into full code execution.&lt;/p&gt;
&lt;p&gt;The fix is trivial: always pass a format string literal. &lt;code&gt;printf(&amp;quot;%s&amp;quot;, buf)&lt;/code&gt;
instead of &lt;code&gt;printf(buf)&lt;/code&gt;. Yet this class of bug resurfaces in embedded firmware
to this day.&lt;/p&gt;
&lt;p&gt;Why does this still happen? Because logging code is often treated as harmless,
copied fast, and reviewed late. In small C projects, developers optimize for
speed of implementation and forget that formatting functions are tiny parsers
with side effects.&lt;/p&gt;
&lt;h2 id=&#34;exploitation-ladder&#34;&gt;Exploitation ladder&lt;/h2&gt;
&lt;p&gt;Typical progression in a lab binary:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Leak stack values with &lt;code&gt;%x&lt;/code&gt; and locate attacker-controlled bytes.&lt;/li&gt;
&lt;li&gt;Calibrate offsets until output is deterministic.&lt;/li&gt;
&lt;li&gt;Use width specifiers to control write count.&lt;/li&gt;
&lt;li&gt;Trigger &lt;code&gt;%n&lt;/code&gt; (or &lt;code&gt;%hn&lt;/code&gt;) to write controlled values to target addresses.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;At that point, you can often redirect flow indirectly by corrupting function
pointers, GOT entries (where applicable), or security-relevant flags.&lt;/p&gt;
&lt;h2 id=&#34;defensive-pattern&#34;&gt;Defensive pattern&lt;/h2&gt;
&lt;p&gt;Treat every formatting call as a sink:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;enforce literal format strings in coding guidelines&lt;/li&gt;
&lt;li&gt;compile with warnings that detect non-literal format usage&lt;/li&gt;
&lt;li&gt;isolate logging wrappers so raw &lt;code&gt;printf&lt;/code&gt; calls are rare&lt;/li&gt;
&lt;li&gt;review embedded diagnostics paths as carefully as network parsers&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Related reading:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://turbovision.in6-addr.net/hacking/exploits/buffer-overflow-101/&#34;&gt;Buffer Overflow 101&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://turbovision.in6-addr.net/hacking/tools/ghidra-first-steps/&#34;&gt;Ghidra: First Steps in Reverse Engineering&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
    </item>
    
    <item>
      <title>Buffer Overflow 101</title>
      <link>https://turbovision.in6-addr.net/hacking/exploits/buffer-overflow-101/</link>
      <pubDate>Mon, 03 Nov 2025 00:00:00 +0000</pubDate>
      <lastBuildDate>Sun, 22 Feb 2026 15:49:37 +0100</lastBuildDate>
      <guid>https://turbovision.in6-addr.net/hacking/exploits/buffer-overflow-101/</guid>
      <description>&lt;p&gt;A stack-based buffer overflow is the oldest trick in the book and still one of the
most instructive. We start with a vulnerable C program, compile it without canaries,
and walk through EIP control step by step.&lt;/p&gt;
&lt;p&gt;The target binary accepts user input via &lt;code&gt;gets()&lt;/code&gt; — a function so dangerous that
modern compilers emit a warning just for including it. We feed it a carefully
crafted payload: 64 bytes of padding, followed by the address of our shellcode
sitting on the stack.&lt;/p&gt;
&lt;p&gt;Key takeaways: always compile test binaries with &lt;code&gt;-fno-stack-protector -z execstack&lt;/code&gt;
when learning, and never on a production box.&lt;/p&gt;
&lt;p&gt;What makes this topic timeless is not the exact exploit recipe, but the mental
model it gives you: memory layout, calling convention, control-flow integrity,
and why unsafe copy primitives are dangerous by construction.&lt;/p&gt;
&lt;h2 id=&#34;reliable-lab-workflow&#34;&gt;Reliable lab workflow&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;Confirm binary protections (&lt;code&gt;checksec&lt;/code&gt; style checks).&lt;/li&gt;
&lt;li&gt;Crash with pattern input to find exact overwrite offset.&lt;/li&gt;
&lt;li&gt;Validate instruction pointer control with marker values.&lt;/li&gt;
&lt;li&gt;Build payload in small increments and verify each stage.&lt;/li&gt;
&lt;li&gt;Only then attempt shellcode or return-oriented payloads.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Expected outcome before each run should be explicit. If behavior differs, do
not &amp;ldquo;try random bytes&amp;rdquo;; explain the difference first. That habit turns exploit
practice into engineering instead of cargo cult.&lt;/p&gt;
&lt;h2 id=&#34;defensive-mirror&#34;&gt;Defensive mirror&lt;/h2&gt;
&lt;p&gt;Learning offensive mechanics should immediately map to mitigation:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;remove dangerous APIs (&lt;code&gt;gets&lt;/code&gt;, unchecked &lt;code&gt;strcpy&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;enable stack canaries, NX, PIE, and RELRO&lt;/li&gt;
&lt;li&gt;reduce attack surface in parser and input-heavy code paths&lt;/li&gt;
&lt;li&gt;test with sanitizers during development&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Related reading:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://turbovision.in6-addr.net/hacking/exploits/format-string-attacks/&#34;&gt;Format String Attacks Demystified&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://turbovision.in6-addr.net/hacking/tools/ghidra-first-steps/&#34;&gt;Ghidra: First Steps in Reverse Engineering&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
    </item>
    
  </channel>
</rss>
