{"id":832,"date":"2015-03-08T18:56:12","date_gmt":"2015-03-08T18:56:12","guid":{"rendered":"https:\/\/www.hackmethod.com\/?p=832"},"modified":"2022-06-03T05:39:11","modified_gmt":"2022-06-03T05:39:11","slug":"overthewire-bandit-22","status":"publish","type":"post","link":"https:\/\/hackmethod.com\/overthewire-bandit-22\/","title":{"rendered":"OvertheWire &#8211; Bandit 22"},"content":{"rendered":"<p>[et_pb_section fb_built=&#8221;1&#8243; admin_label=&#8221;section&#8221; _builder_version=&#8221;3.22&#8243;][et_pb_row admin_label=&#8221;row&#8221; _builder_version=&#8221;3.25&#8243; background_size=&#8221;initial&#8221; background_position=&#8221;top_left&#8221; background_repeat=&#8221;repeat&#8221;][et_pb_column type=&#8221;4_4&#8243; _builder_version=&#8221;3.25&#8243; custom_padding=&#8221;|||&#8221; custom_padding__hover=&#8221;|||&#8221;][et_pb_text admin_label=&#8221;Text&#8221; _builder_version=&#8221;4.7.5&#8243; background_size=&#8221;initial&#8221; background_position=&#8221;top_left&#8221; background_repeat=&#8221;repeat&#8221; hover_enabled=&#8221;0&#8243; sticky_enabled=&#8221;0&#8243;]<strong>Recap of Level 21:<\/strong> Learned about creating a simple data communication link between hosts.<strong><br \/> <\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/overthewire.org\/wargames\/bandit\/bandit22.html\" target=\"_blank\" rel=\"noopener\"><strong>Bandit Level 22<\/strong><\/a><\/p>\n<h4><strong>Objective:<\/strong><\/h4>\n<p>Find the password to the next level<\/p>\n<h4><strong>Intel Given:<\/strong><\/h4>\n<p>A program is running automatically at regular intervals from <b>cron<\/b>, the time-based job scheduler. Look in <b>\/etc\/cron.d\/<\/b> for the configuration and see what command is being executed.<\/p>\n<p><!--more--><\/p>\n<h4><strong>How to:<\/strong><\/h4>\n<p>Our intel seems pretty straightforward for this level. There\u2019s a script in cron, the script scheduler that let\u2019s users and programs create and select scripts and programs to execute at a certain time, that contains the password. Cron can be used to schedule things to run daily, weekly, monthly, or hourly. It is a powerful tool to automatically set up backups, download and install updates, and anything else that needs to be run at a certain time. Our intel suggests that we should look in the cron directory so let\u2019s take a look.<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/www.hackmethod.com\/wp-content\/uploads\/2015\/03\/bandit22-1.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-827 size-full\" src=\"https:\/\/i0.wp.com\/www.hackmethod.com\/wp-content\/uploads\/2015\/03\/bandit22-1.png?resize=649%2C146&#038;ssl=1\" alt=\"bandit22-1\" style=\"display: block; margin-left: auto; margin-right: auto;\" width=\"649\" height=\"146\" \/><\/a><\/p>\n<p>cronjob_bandit22 looks promising so let\u2019s open it up. Cron\u2019s format is a little unorthodox so let\u2019s take a look. there are 5 spaces for specifying what time to run the script or program. If the space isn\u2019t needed a star is used as a placeholder. The first position is used to denote , the minute using a value between 0-59. The second one is hour, using the 24 hour clock, meaning values between 0-23. The third place is used for day of the month, \u00a0using values ranging from 1-31. The fourth space is month, specified by numbers between 1-12. The fifth position is used for day of the week, depending on the distribution 0 or 7 could be Sunday, I recommend checking on any distribution that you\u2019re not sure about. The next part of a cron job is the username that executes the job. The final part of the cron job command is the script or program that is to be executed.<\/p>\n<p>If you\u2019re having trouble visualizing this here\u2019s a graphic from adminschoice.com<\/p>\n<p>* \u00a0\u00a0\u00a0 * \u00a0\u00a0 * \u00a0\u00a0 * \u00a0\u00a0\u00a0 * \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0command to be executed<br \/> &#8211; \u00a0\u00a0\u00a0 &#8211;\u00a0\u00a0\u00a0 &#8211; \u00a0\u00a0 &#8211; \u00a0\u00a0 &#8211;<br \/> | \u00a0\u00a0\u00a0 | \u00a0\u00a0\u00a0 | \u00a0\u00a0\u00a0 |\u00a0\u00a0\u00a0 |<br \/> | \u00a0\u00a0\u00a0 | \u00a0\u00a0\u00a0 | \u00a0\u00a0\u00a0 |\u00a0\u00a0\u00a0 +&#8212;&#8211; day of week (0 &#8211; 6) (Sunday=0)<br \/> | \u00a0\u00a0\u00a0 | \u00a0\u00a0\u00a0 | \u00a0\u00a0\u00a0 +&#8212;&#8212;- month (1 &#8211; 12)<br \/> | \u00a0\u00a0\u00a0 | \u00a0\u00a0\u00a0 +&#8212;&#8212;&#8212; day of \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0month (1 &#8211; 31)<br \/> | \u00a0\u00a0\u00a0 +&#8212;&#8212;&#8212;&#8211; hour (0 &#8211; 23)<br \/> +&#8212;&#8212;&#8212;&#8212;- min (0 &#8211; 59)<\/p>\n<p>There\u2019s also a tool for showing what a proper cron configuration should look like for whatever you would like at corntab.com <a href=\"http:\/\/www.corntab.com\/pages\/crontab-gui\">http:\/\/www.corntab.com\/pages\/crontab-gui<\/a>.\u00a0<em>Edit: User Christian has emailed us and told of us another cool alternative\u00a0<a href=\"http:\/\/crontab.guru\/\" target=\"_blank\" rel=\"noopener\">http:\/\/crontab.guru\/<\/a><\/em><\/p>\n<p>Now that we know the basics of cron let\u2019s take a look at the script we have at hand.<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/www.hackmethod.com\/wp-content\/uploads\/2015\/03\/bandit22-2.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-828\" src=\"https:\/\/i0.wp.com\/www.hackmethod.com\/wp-content\/uploads\/2015\/03\/bandit22-2.png?resize=557%2C41&#038;ssl=1\" alt=\"bandit22-2\" style=\"display: block; margin-left: auto; margin-right: auto;\" width=\"557\" height=\"41\" \/><\/a><\/p>\n<p>Looks like this script is set to run every minute of every hour of every day of the month of every month and every day of the week. If this had been a resource intense one like a backup across a network it could cause some serious problems. I have a feeling, however that it is pretty small and doesn\u2019t take up a lot of resources. So to further investigate let\u2019s see what the script does.<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/www.hackmethod.com\/wp-content\/uploads\/2015\/03\/bandit22-3.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-829\" src=\"https:\/\/i0.wp.com\/www.hackmethod.com\/wp-content\/uploads\/2015\/03\/bandit22-3.png?resize=629%2C77&#038;ssl=1\" alt=\"bandit22-3\" style=\"display: block; margin-left: auto; margin-right: auto;\" width=\"629\" height=\"77\" \/><\/a><\/p>\n<p>looks like this script changes the file permissions of a file in the \/tmp\/ directory to enable the read and write permission for the user, and read permission for the group and everyone else. The \/tmp directory is similar to the temp file folder in Windows, it\u2019s used to create random directory and file names for use in programs and scripts. The second line in the script looks like it reads the file bandit22 in the \/etc\/bandit_pass\/ directory and then uses the greater than sign (&gt;). In Linux this is used to write text from one file to another, so the file bandit22 is essentially being copied to the \/tmp\/t7O6lds9S0RqQh9aMcz6ShpAoZKF7fgv file. If we wanted to write more than one file to a file we would have to add another of the brackets like so &gt;&gt;, this tells the shell that instead of writing over the file to add them to the bottom of the file. This technique is mostly used to write outputs to logs that otherwise would go to the standard output. Anyway let\u2019s find that password.<\/p>\n<p>The script wrote it to the file in the \/tmp\/ directory so let\u2019s try to cat it.<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/www.hackmethod.com\/wp-content\/uploads\/2015\/03\/bandit22-4.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-830\" src=\"https:\/\/i0.wp.com\/www.hackmethod.com\/wp-content\/uploads\/2015\/03\/bandit22-4.png?resize=636%2C35&#038;ssl=1\" alt=\"bandit22-4\" style=\"display: block; margin-left: auto; margin-right: auto;\" width=\"636\" height=\"35\" \/><\/a><\/p>\n<p>Alright looks good!<\/p>\n<h4><strong>Conclusion:<\/strong><\/h4>\n<p>We learned about how cron works, a little bit about scripts, and how to write files using cat.<\/p>\n<p>[\/et_pb_text][\/et_pb_column][\/et_pb_row][et_pb_row _builder_version=&#8221;4.7.5&#8243; _module_preset=&#8221;default&#8221; column_structure=&#8221;1_2,1_2&#8243;][et_pb_column _builder_version=&#8221;4.7.5&#8243; _module_preset=&#8221;default&#8221; type=&#8221;1_2&#8243;][et_pb_image src=&#8221;https:\/\/hackmethod.com\/wp-content\/uploads\/2020\/12\/Previous.png&#8221; _builder_version=&#8221;4.7.5&#8243; _module_preset=&#8221;default&#8221; alt=&#8221;Previous Level&#8221; title_text=&#8221;Previous&#8221; url=&#8221;https:\/\/hackmethod.com\/overthewire-bandit-21&#8243; hover_enabled=&#8221;0&#8243; sticky_enabled=&#8221;0&#8243;][\/et_pb_image][\/et_pb_column][et_pb_column _builder_version=&#8221;4.7.5&#8243; _module_preset=&#8221;default&#8221; type=&#8221;1_2&#8243;][et_pb_image src=&#8221;https:\/\/hackmethod.com\/wp-content\/uploads\/2020\/12\/Next.png&#8221; _builder_version=&#8221;4.7.5&#8243; _module_preset=&#8221;default&#8221; alt=&#8221;Next Level&#8221; title_text=&#8221;Next&#8221; url=&#8221;https:\/\/hackmethod.com\/overthewire-bandit-23&#8243; align=&#8221;right&#8221; hover_enabled=&#8221;0&#8243; sticky_enabled=&#8221;0&#8243;][\/et_pb_image][\/et_pb_column][\/et_pb_row][\/et_pb_section]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recap of Level 21: Learned about creating a simple data communication link between hosts. &nbsp; Bandit Level 22 Objective: Find the password to the next level Intel Given: A program is running automatically at regular intervals from cron, the time-based job scheduler. Look in \/etc\/cron.d\/ for the configuration and see what command is being executed. [&hellip;]<\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"on","_et_pb_old_content":"<strong>Recap of <a href=\"https:\/\/www.hackmethod.com\/overthewire-bandit-21\/\" target=\"_blank\">Last\u00a0Lesson<\/a>:<\/strong> Learned about creating a simple data communication link between hosts<strong>\r\n<\/strong>\r\n\r\n<a href=\"http:\/\/overthewire.org\/wargames\/bandit\/bandit22.html\" target=\"_blank\"><strong>Bandit Level 22<\/strong><\/a>\r\n\r\n<strong>Objective<\/strong>\r\n\r\nFind the password to the next level\r\n\r\n<strong>Intel Given<\/strong>\r\n\r\nA program is running automatically at regular intervals from <b>cron<\/b>, the time-based job scheduler. Look in <b>\/etc\/cron.d\/<\/b> for the configuration and see what command is being executed.\r\n\r\n<!--more-->\r\n\r\n<strong>How to<\/strong>\r\n\r\nOur intel seems pretty straightforward for this level. There\u2019s a script in cron, the script scheduler that let\u2019s users and programs create and select scripts and programs to execute at a certain time, that contains the password. Cron can be used to schedule things to run daily, weekly, monthly, or hourly. It is a powerful tool to automatically set up backups, download and install updates, and anything else that needs to be run at a certain time. Our intel suggests that we should look in the cron directory so let\u2019s take a look.\r\n\r\n<a href=\"https:\/\/www.hackmethod.com\/wp-content\/uploads\/2015\/03\/bandit22-1.png\"><img class=\"alignnone wp-image-827 size-full\" src=\"https:\/\/www.hackmethod.com\/wp-content\/uploads\/2015\/03\/bandit22-1.png\" alt=\"bandit22-1\" width=\"649\" height=\"146\" \/><\/a>\r\n\r\ncronjob_bandit22 looks promising so let\u2019s open it up. Cron\u2019s format is a little unorthodox so let\u2019s take a look. there are 5 spaces for specifying what time to run the script or program. If the space isn\u2019t needed a star is used as a placeholder. The first position is used to denote , the minute using a value between 0-59. The second one is hour, using the 24 hour clock, meaning values between 0-23. The third place is used for day of the month, \u00a0using values ranging from 1-31. The fourth space is month, specified by numbers between 1-12. The fifth position is used for day of the week, depending on the distribution 0 or 7 could be Sunday, I recommend checking on any distribution that you\u2019re not sure about. The next part of a cron job is the username that executes the job. The final part of the cron job command is the script or program that is to be executed.\r\n\r\nIf you\u2019re having trouble visualizing this here\u2019s a graphic from adminschoice.com\r\n\r\n* \u00a0\u00a0\u00a0 * \u00a0\u00a0 * \u00a0\u00a0 * \u00a0\u00a0\u00a0 * \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0command to be executed\r\n- \u00a0\u00a0\u00a0 -\u00a0\u00a0\u00a0 - \u00a0\u00a0 - \u00a0\u00a0 -\r\n| \u00a0\u00a0\u00a0 | \u00a0\u00a0\u00a0 | \u00a0\u00a0\u00a0 |\u00a0\u00a0\u00a0 |\r\n| \u00a0\u00a0\u00a0 | \u00a0\u00a0\u00a0 | \u00a0\u00a0\u00a0 |\u00a0\u00a0\u00a0 +----- day of week (0 - 6) (Sunday=0)\r\n| \u00a0\u00a0\u00a0 | \u00a0\u00a0\u00a0 | \u00a0\u00a0\u00a0 +------- month (1 - 12)\r\n| \u00a0\u00a0\u00a0 | \u00a0\u00a0\u00a0 +--------- day of \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0month (1 - 31)\r\n| \u00a0\u00a0\u00a0 +----------- hour (0 - 23)\r\n+------------- min (0 - 59)\r\n\r\nThere\u2019s also a tool for showing what a proper cron configuration should look like for whatever you would like at corntab.com <a href=\"http:\/\/www.corntab.com\/pages\/crontab-gui\">http:\/\/www.corntab.com\/pages\/crontab-gui<\/a>.\u00a0<em>Edit: User Christian has emailed us and told of us another cool alternative\u00a0<a href=\"http:\/\/crontab.guru\/\" target=\"_blank\">http:\/\/crontab.guru\/<\/a><\/em>\r\n\r\nNow that we know the basics of cron let\u2019s take a look at the script we have at hand.\r\n\r\n<a href=\"https:\/\/www.hackmethod.com\/wp-content\/uploads\/2015\/03\/bandit22-2.png\"><img class=\"alignnone size-full wp-image-828\" src=\"https:\/\/www.hackmethod.com\/wp-content\/uploads\/2015\/03\/bandit22-2.png\" alt=\"bandit22-2\" width=\"557\" height=\"41\" \/><\/a>\r\n\r\nLooks like this script is set to run every minute of every hour of every day of the month of every month and every day of the week. If this had been a resource intense one like a backup across a network it could cause some serious problems. I have a feeling, however that it is pretty small and doesn\u2019t take up a lot of resources. So to further investigate let\u2019s see what the script does.\r\n\r\n<a href=\"https:\/\/www.hackmethod.com\/wp-content\/uploads\/2015\/03\/bandit22-3.png\"><img class=\"alignnone size-full wp-image-829\" src=\"https:\/\/www.hackmethod.com\/wp-content\/uploads\/2015\/03\/bandit22-3.png\" alt=\"bandit22-3\" width=\"629\" height=\"77\" \/><\/a>\r\n\r\nlooks like this script changes the file permissions of a file in the \/tmp\/ directory to enable the read and write permission for the user, and read permission for the group and everyone else. The \/tmp directory is similar to the temp file folder in Windows, it\u2019s used to create random directory and file names for use in programs and scripts. The second line in the script looks like it reads the file bandit22 in the \/etc\/bandit_pass\/ directory and then uses the greater than sign (&gt;). In Linux this is used to write text from one file to another, so the file bandit22 is essentially being copied to the \/tmp\/t7O6lds9S0RqQh9aMcz6ShpAoZKF7fgv file. If we wanted to write more than one file to a file we would have to add another of the brackets like so &gt;&gt;, this tells the shell that instead of writing over the file to add them to the bottom of the file. This technique is mostly used to write outputs to logs that otherwise would go to the standard output. Anyway let\u2019s find that password.\r\n\r\nThe script wrote it to the file in the \/tmp\/ directory so let\u2019s try to cat it.\r\n\r\n<a href=\"https:\/\/www.hackmethod.com\/wp-content\/uploads\/2015\/03\/bandit22-4.png\"><img class=\"alignnone size-full wp-image-830\" src=\"https:\/\/www.hackmethod.com\/wp-content\/uploads\/2015\/03\/bandit22-4.png\" alt=\"bandit22-4\" width=\"636\" height=\"35\" \/><\/a>\r\n\r\nAlright looks good!\r\n\r\n<strong>Conclusion<\/strong>\r\n\r\nWe learned about how cron works, a little bit about scripts, and how to write files using cat.","_et_gb_content_width":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[52,44,49],"tags":[43,45,46],"class_list":["post-832","post","type-post","status-publish","format-standard","hentry","category-hacking","category-overthewire","category-tutorials","tag-bandit","tag-overthewire","tag-tutorials"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p5zY4D-dq","_links":{"self":[{"href":"https:\/\/hackmethod.com\/wp-json\/wp\/v2\/posts\/832","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hackmethod.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hackmethod.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hackmethod.com\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/hackmethod.com\/wp-json\/wp\/v2\/comments?post=832"}],"version-history":[{"count":7,"href":"https:\/\/hackmethod.com\/wp-json\/wp\/v2\/posts\/832\/revisions"}],"predecessor-version":[{"id":27570,"href":"https:\/\/hackmethod.com\/wp-json\/wp\/v2\/posts\/832\/revisions\/27570"}],"wp:attachment":[{"href":"https:\/\/hackmethod.com\/wp-json\/wp\/v2\/media?parent=832"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hackmethod.com\/wp-json\/wp\/v2\/categories?post=832"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hackmethod.com\/wp-json\/wp\/v2\/tags?post=832"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}