{"id":16,"date":"2012-07-18T20:37:05","date_gmt":"2012-07-19T03:37:05","guid":{"rendered":"http:\/\/seanmurphree.com\/blog\/?p=16"},"modified":"2012-08-02T00:17:41","modified_gmt":"2012-08-02T07:17:41","slug":"hello-world-aka-io-level1","status":"publish","type":"post","link":"https:\/\/seanmurphree.com\/blog\/?p=16","title":{"rendered":"Hello World!  (AKA IO Level1 &#8211; Strings)"},"content":{"rendered":"<p>Hello all and welcome to the first posting here at Technolution.<\/p>\n<p>While this blog is supposed to be about computers, networking, security, and all that fun stuff, I feel like a good place to start posting would be with a wargame dissection. \u00a0For those unfamiliar with wargames, they are basically computers set up for practicing real-world computer security in a controlled and legal environment. \u00a0This provides hands on experience with the type of situations in which security researchers and hackers have found and exploited computer security vulnerabilities. \u00a0There are many types of wargames, from web interface based games to linux command-line based games, and anything in between.<\/p>\n<p>Today we will start off with the first level of a linux command-line based game called <a title=\"IO\" href=\"http:\/\/io.smashthestack.org:84\/\" target=\"_blank\">IO<\/a>, from the good folks over at <a title=\"SmashTheStack.org\" href=\"http:\/\/www.smashthestack.org\" target=\"_blank\">SmashTheStack.org<\/a>.<\/p>\n<p>Reading the IO page, it states that one should use an ssh client to connect to port 2224 of io.smashthestack.org using the login &#8220;level1&#8221; and the password &#8220;level1&#8221;. \u00a0For linux users the command is provided (and hopefully you don&#8217;t need it),\u00a0ssh -p2224 level1@io.smashthestack.org. \u00a0Windows users I suggest downloading and using PuTTy for your SSH work.<\/p>\n<p>Quick directory listing (ls) gives a bunch of README files. \u00a0Reading through the README in our language, we learn the programs to exploit to reach the next level are in \/levels \u00a0So, we change directories to \/levels (cd \/levels) and get a listing (ls). \u00a0There are lots of files, named level01 &#8211; level29, mostly executables and some source files. \u00a0Most importantly however, we found the file level01. \u00a0Running ls -la level01 we can see two things.<\/p>\n<blockquote><p>level1@io:\/levels$ ls -la level01<br \/>\n-r-sr-x&#8212; 1 level2 level1 7500 Nov 16 2007 level01<\/p><\/blockquote>\n<p>One is that the file is owned by user level2 and is set to run as that user, even when someone else runs it (SUID, the &#8220;s&#8221; in the permissions listing -r-sr-x&#8212;). \u00a0Second is that the group for the file is our current group, level1. \u00a0This means that we can execute the file since the file permissions grant group reading and executing (the 5,6,7 column in the permissions string, r-x). \u00a0Excellent! \u00a0Now we just need to exploit the file!<\/p>\n<p>First we want to see what the file does, so try to run it.<\/p>\n<blockquote><p>level1@io:\/levels$ .\/level01<br \/>\nUsage: .\/level01 &lt;password&gt;<br \/>\nlevel1@io:\/levels$ .\/level01 somepassword<br \/>\nFail.<\/p><\/blockquote>\n<p>Ok. \u00a0We believe the program takes one argument, a password. \u00a0It also probably checks the input-password being equal to something (how else would it know if we input the correct thing?) \u00a0So the first thing we want to do is see if the program stores any constant strings. \u00a0Luckily in linux, there is a tool to do this and we don&#8217;t have to binarily dissect the file ourselves. \u00a0The tool provided is called, dun dun dun, strings. \u00a0It&#8217;s use is straight forward, strings &lt;filename&gt;. \u00a0So lets see what happens when we run our level01 program through strings, looking for hard-coded, constant strings.<\/p>\n<blockquote><p>level1@io:\/levels$ strings level01<br \/>\n\/lib\/ld-linux.so.2<br \/>\n__gmon_start__<br \/>\nlibc.so.6<br \/>\nprintf<br \/>\nexecl<br \/>\nputs<br \/>\nstrncmp<br \/>\n_IO_stdin_used<br \/>\n__libc_start_main<br \/>\nGLIBC_2.0<br \/>\nPTRh<br \/>\n0Y_]<br \/>\n[^_]<br \/>\n[^_]<br \/>\nomgpassword<br \/>\nUsage: %s &lt;password&gt;<br \/>\nWin.<br \/>\n\/bin\/sh<br \/>\nFail.<\/p><\/blockquote>\n<p>We see what we&#8217;d expect, a few hard-coded strings for libraries and for function names from libs. \u00a0But further down, towards the end, we see the strings &#8220;omgpassword&#8221; &#8220;Usage: %s &lt;password&gt;&#8221; &#8220;Win.&#8221; &#8220;\/bin\/sh&#8221; and &#8220;Fail.&#8221; \u00a0We&#8217;ve already seen the program use the Usage string and the Fail. string. \u00a0Obviously we probably want to see the program use the Win string and execute the \/bin\/sh string. \u00a0Now, it&#8217;s probably obvious we want to try all the strings as possible passwords, through the real password is jumping out at us (I think?). \u00a0So let&#8217;s try it, omgpassword:<\/p>\n<blockquote><p>level1@io:\/levels$ .\/level01 omgpassword<br \/>\nWin.<br \/>\nsh-4.1$ id<br \/>\nuid=1001(level1) gid=1001(level1) euid=1002(level2) groups=1002(level2),1001(level1),1029(nosu)<br \/>\nsh-4.1$<\/p><\/blockquote>\n<p>Bam. \u00a0Shell as level02.<\/p>\n<p>Moral of the story? \u00a0Hard-coded strings are readable if the file is readable. \u00a0Doesn&#8217;t matter if you have to use strings &lt;filename&gt; or dissect the binary data of the file, reading each sequence of bytes as chars, or anything else. \u00a0Plain text is plain text. \u00a0Constant, hard-coded strings are stored in plain text. \u00a0Thus, it&#8217;s not secure. \u00a0It may be a deterrent, but it&#8217;s not secure.<\/p>\n<p>Well that does it for Level 1 of IO, and the first post here at Technolution. \u00a0Remember to always ask why and how something works, and if no one wants to talk about it, there&#8217;s probably a problem with it! \u00a0Also, if anyone is making new wargames, or has something fresh to approach, please leave a comment!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello all and welcome to the first posting here at Technolution. While this blog is supposed to be about computers, networking, security, and all that fun stuff, I feel like a good place to start posting would be with a &hellip; <a href=\"https:\/\/seanmurphree.com\/blog\/?p=16\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[8,6,4],"tags":[],"_links":{"self":[{"href":"https:\/\/seanmurphree.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/16"}],"collection":[{"href":"https:\/\/seanmurphree.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/seanmurphree.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/seanmurphree.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/seanmurphree.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=16"}],"version-history":[{"count":5,"href":"https:\/\/seanmurphree.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/16\/revisions"}],"predecessor-version":[{"id":173,"href":"https:\/\/seanmurphree.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/16\/revisions\/173"}],"wp:attachment":[{"href":"https:\/\/seanmurphree.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=16"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanmurphree.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=16"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanmurphree.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=16"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}