This code locates the variable on the heap, and replaces it's value. it's curious that print uses syscall SYS_write but write is not triggering that syscall.
$findme="olsijdf9823"; $len=length($findme); $pid=$$; #"self"; $heap=`cat /proc/$pid/maps | grep heap | cut -d ' ' -f 1`; $stack=`cat /proc/$pid/maps | grep stack | cut -d ' ' -f 1`; print("my pid is $pid\n"); #while(){sleep 1;} if ($heap =~ /([a-f0-9]+)-([a-f0-9]+)/) { $start_heap = hex($1); $end_heap = hex($2); } if ($stack =~ /([a-f0-9]+)-([a-f0-9]+)/) { $start_stack = hex($1); $end_stack = hex($2); } open(MEM, "+<", "/proc/$pid/mem") or die "no permissions"; for $addr ($start_heap..$end_heap) { seek(MEM, $addr, 0); read(MEM, $buff, $len, 0); #print(sprintf("0x%x %s\n", $addr, $buff)); if ($buff eq $findme) { print("found\n"); seek(MEM, $addr, 0); print(MEM "hacked\x00"); } } close(MEM); `sync`; print "---> $findme \n"; #EOF
Execution:
$ perl test.pl my pid is 127249 found ---> hacked9823
Other detail is that \x00 is not an string terminator on perl, probably its a structure with a length item.

In reply to altering it's own heap by sha0coder

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.