{"id":97,"date":"2021-10-06T12:53:56","date_gmt":"2021-10-06T10:53:56","guid":{"rendered":"https:\/\/areyou1or0.it\/?p=97"},"modified":"2021-10-10T21:13:02","modified_gmt":"2021-10-10T19:13:02","slug":"slae64-assignment-1-bind-shell","status":"publish","type":"post","link":"https:\/\/areyou1or0.it\/index.php\/2021\/10\/06\/slae64-assignment-1-bind-shell\/","title":{"rendered":"SLAE64: Assignment 1 &#8211; Bind Shell"},"content":{"rendered":"\n<p>This blog post has been created for completing the requirements of the SecurityTube Linux Assembly Expert (SLAE64) certification:<\/p>\n\n\n\n<p><a href=\"https:\/\/www.pentesteracademy.com\/course?id=7\">https:\/\/www.pentesteracademy.com\/course?id=7<\/a><\/p>\n\n\n\n<p>Student-ID: <strong>PA-15847<\/strong><\/p>\n\n\n\n<p>The Objectives for the Assignment:<\/p>\n\n\n\n<p><code><strong>create a shell_bind_tcp shellcode<\/strong><\/code><\/p>\n\n\n\n<ul><li><code><strong>binds to a port<\/strong><\/code><\/li><li><code><strong>needs a passcode<\/strong><\/code><\/li><li><code><strong>if passcode is correct, then execs shell<\/strong><\/code><\/li><li><strong><code>remove 0x00 from bind tcp shellcode<\/code><\/strong><\/li><\/ul>\n\n\n\n<p>So I took the code written during the course as a base and developed the remaining parts as below:<\/p>\n\n\n\n<p>I use the following syscalls in the same order:<\/p>\n\n\n\n<p><code><strong>syscall: socket --&gt; open a socket<br>syscall bind --&gt; binding the shell to IP and port<br>syscalls.listen --&gt; listen for incoming connections<br>syscalls.accept --&gt; accept incoming connections<br>syscalls.dup2<br>syscall.read --&gt; to read the password<br>syscalls.execve<br>syscalls.close<\/strong><\/code><\/p>\n\n\n\n<p>It&#8217;s important to understand the arguments for each syscall and how do we write it in assembly as it&#8217;s been taught during the course. <\/p>\n\n\n\n<p>Here&#8217;re the assembly code that I wrote per syscall. I also explained some of the lines with a comment in case it&#8217;s unclear:<\/p>\n\n\n\n<p>First we open a socket (syscall number:41) with the following syntax<\/p>\n\n\n\n<p><code><strong>int socket(int<\/strong>&nbsp;<em>domain<\/em><strong>, int<\/strong>&nbsp;<em>type<\/em><strong>, int<\/strong>&nbsp;<em>protocol<\/em><strong>);<\/strong><\/code><\/p>\n\n\n\n<p>We&#8217;ll have the following values for the arguments:<\/p>\n\n\n\n<p><code>$ <strong>python<\/strong><\/code><\/p>\n\n\n\n<p><code><strong>&gt;&gt;&gt; import socket<br>&gt;&gt;&gt; socket.AF_INET<br>2<br>&gt;&gt;&gt; socket.SOCK_STREAM<br>1<br>&gt;&gt;&gt; socket.INADDR_ANY<br>0<\/strong><\/code><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"919\" height=\"488\" src=\"https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-06-at-12.34.20.png\" alt=\"\" class=\"wp-image-98\" srcset=\"https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-06-at-12.34.20.png 919w, https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-06-at-12.34.20-300x159.png 300w, https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-06-at-12.34.20-768x408.png 768w, https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-06-at-12.34.20-600x319.png 600w\" sizes=\"(max-width: 919px) 100vw, 919px\" \/><figcaption>syscall: socket<\/figcaption><\/figure>\n\n\n\n<p>Then we&#8217;ll use bind syscall to bind the shell to an IP and port with the following syntax<\/p>\n\n\n\n<p><code><strong>int bind(int<\/strong>&nbsp;<em>sockfd<\/em><strong>, const struct sockaddr<\/strong>&nbsp;<em>addr<\/em><strong>,<\/strong>&nbsp;<strong>socklen_t<\/strong>&nbsp;<em>addrlen<\/em><strong>);<\/strong><\/code><\/p>\n\n\n\n<p>We&#8217;ll use the following values:<\/p>\n\n\n\n<p><code><strong>0.0.0.0 (IP), 4444 (port) and  2 (address family AF_INET)<\/strong><\/code><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"387\" src=\"https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-06-at-12.34.45-1024x387.png\" alt=\"\" class=\"wp-image-99\" srcset=\"https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-06-at-12.34.45-1024x387.png 1024w, https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-06-at-12.34.45-300x113.png 300w, https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-06-at-12.34.45-768x290.png 768w, https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-06-at-12.34.45-600x227.png 600w, https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-06-at-12.34.45.png 1270w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption>syscall: bind<\/figcaption><\/figure>\n\n\n\n<p>Then we&#8217;ll use listen syscall to listen for incoming connections with the following syntax:<\/p>\n\n\n\n<p><code><strong>int listen(int<\/strong>&nbsp;<em>sockfd<\/em>,&nbsp;<strong>int<\/strong>&nbsp;<em>backlog<\/em><strong>);<\/strong><\/code><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"982\" height=\"326\" src=\"https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-06-at-12.34.51.png\" alt=\"\" class=\"wp-image-100\" srcset=\"https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-06-at-12.34.51.png 982w, https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-06-at-12.34.51-300x100.png 300w, https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-06-at-12.34.51-768x255.png 768w, https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-06-at-12.34.51-600x199.png 600w\" sizes=\"(max-width: 982px) 100vw, 982px\" \/><figcaption>syscall listen<\/figcaption><\/figure>\n\n\n\n<p>Next, we&#8217;ll use accept syscall for incoming connections with the following syntax:<\/p>\n\n\n\n<p><code><strong>int accept(int<\/strong>&nbsp;sockfd,&nbsp;<strong>struct<\/strong>&nbsp;sockaddr&nbsp;<em>addr<\/em>,&nbsp;<strong>socklen_t<\/strong>&nbsp;<em>addrlen<\/em><strong>);<\/strong><\/code><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"293\" src=\"https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-06-at-12.35.01-1024x293.png\" alt=\"\" class=\"wp-image-101\" srcset=\"https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-06-at-12.35.01-1024x293.png 1024w, https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-06-at-12.35.01-300x86.png 300w, https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-06-at-12.35.01-768x219.png 768w, https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-06-at-12.35.01-600x171.png 600w, https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-06-at-12.35.01.png 1246w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption>syscall accept<\/figcaption><\/figure>\n\n\n\n<p>Redirection to the socket will be handled with dup2 syscall. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"678\" src=\"https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-06-at-12.35.07-1024x678.png\" alt=\"\" class=\"wp-image-102\" srcset=\"https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-06-at-12.35.07-1024x678.png 1024w, https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-06-at-12.35.07-300x199.png 300w, https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-06-at-12.35.07-768x508.png 768w, https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-06-at-12.35.07-600x397.png 600w, https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-06-at-12.35.07.png 1254w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption>syscall dup2<\/figcaption><\/figure>\n\n\n\n<p>Now it&#8217;s time to ask for the password. We&#8217;ll first read the string using read syscall and then compare its accuracy. It will re ask for the password if the response is incorrect. Here&#8217;s the syntax used for read syscall:<\/p>\n\n\n\n<p><code><strong>ssize_t read(int fd, void *buf, size_t count);<\/strong><\/code><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"505\" src=\"https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-06-at-12.35.13-1024x505.png\" alt=\"\" class=\"wp-image-103\" srcset=\"https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-06-at-12.35.13-1024x505.png 1024w, https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-06-at-12.35.13-300x148.png 300w, https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-06-at-12.35.13-768x378.png 768w, https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-06-at-12.35.13-600x296.png 600w, https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-06-at-12.35.13.png 1112w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption>syscall:read<\/figcaption><\/figure>\n\n\n\n<p>We&#8217;ll execute \/bin\/sh with execve syscall here:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"954\" height=\"660\" src=\"https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-06-at-12.35.18.png\" alt=\"\" class=\"wp-image-104\" srcset=\"https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-06-at-12.35.18.png 954w, https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-06-at-12.35.18-300x208.png 300w, https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-06-at-12.35.18-768x531.png 768w, https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-06-at-12.35.18-600x415.png 600w\" sizes=\"(max-width: 954px) 100vw, 954px\" \/><figcaption>syscall: execve<\/figcaption><\/figure>\n\n\n\n<p>We&#8217;ll close the socket and exit the program at the end. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"682\" height=\"364\" src=\"https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-06-at-12.35.24.png\" alt=\"\" class=\"wp-image-105\" srcset=\"https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-06-at-12.35.24.png 682w, https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-06-at-12.35.24-300x160.png 300w, https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/Screenshot-2021-10-06-at-12.35.24-600x320.png 600w\" sizes=\"(max-width: 682px) 100vw, 682px\" \/><figcaption>syscall:close<\/figcaption><\/figure>\n\n\n\n<p>Then we compiled and linked the files and run the executable to get a bind shell:<\/p>\n\n\n\n<p><code><strong>nasm -felf64 assignment1.nasm -o assignment1.o<\/strong><\/code><\/p>\n\n\n\n<p><code><strong>ld assignment1.o -o assignment1<\/strong><\/code><\/p>\n\n\n\n<p><code><strong>.\/assignment1<\/strong><\/code><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"568\" src=\"https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/assignment1-1024x568.png\" alt=\"\" class=\"wp-image-106\" srcset=\"https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/assignment1-1024x568.png 1024w, https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/assignment1-300x166.png 300w, https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/assignment1-768x426.png 768w, https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/assignment1-1536x852.png 1536w, https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/assignment1-1568x870.png 1568w, https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/assignment1-600x333.png 600w, https:\/\/areyou1or0.it\/wp-content\/uploads\/2021\/10\/assignment1.png 1664w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>This blog post has been created for completing the requirements of the SecurityTube Linux Assembly Expert (SLAE64) certification: https:\/\/www.pentesteracademy.com\/course?id=7 Student-ID: PA-15847 The Objectives for the Assignment: create a shell_bind_tcp shellcode binds to a port needs a passcode if passcode is correct, then execs shell remove 0x00 from bind tcp shellcode So I took the code&hellip; <a class=\"more-link\" href=\"https:\/\/areyou1or0.it\/index.php\/2021\/10\/06\/slae64-assignment-1-bind-shell\/\">Continue reading <span class=\"screen-reader-text\">SLAE64: Assignment 1 &#8211; Bind Shell<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[20],"tags":[],"_links":{"self":[{"href":"https:\/\/areyou1or0.it\/index.php\/wp-json\/wp\/v2\/posts\/97"}],"collection":[{"href":"https:\/\/areyou1or0.it\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/areyou1or0.it\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/areyou1or0.it\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/areyou1or0.it\/index.php\/wp-json\/wp\/v2\/comments?post=97"}],"version-history":[{"count":4,"href":"https:\/\/areyou1or0.it\/index.php\/wp-json\/wp\/v2\/posts\/97\/revisions"}],"predecessor-version":[{"id":159,"href":"https:\/\/areyou1or0.it\/index.php\/wp-json\/wp\/v2\/posts\/97\/revisions\/159"}],"wp:attachment":[{"href":"https:\/\/areyou1or0.it\/index.php\/wp-json\/wp\/v2\/media?parent=97"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/areyou1or0.it\/index.php\/wp-json\/wp\/v2\/categories?post=97"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/areyou1or0.it\/index.php\/wp-json\/wp\/v2\/tags?post=97"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}