<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Python on Such geek. Wow.</title><link>https://www.ericlight.com/tags/python.html</link><description>Recent content in Python on Such geek. Wow.</description><generator>Hugo -- gohugo.io</generator><language>en</language><lastBuildDate>Sat, 27 May 2017 00:00:00 +1200</lastBuildDate><atom:link href="https://www.ericlight.com/tags/python/index.xml" rel="self" type="application/rss+xml"/><item><title>RingZer0team CTF - Challenge 148</title><link>https://www.ericlight.com/post/r0-148.html</link><pubDate>Sat, 27 May 2017 00:00:00 +1200</pubDate><guid>https://www.ericlight.com/post/r0-148.html</guid><description>&lt;p&gt;There are a bunch of fantastic Capture The Flag security challenges on &lt;a class="link" href="https://www.ringzer0team.com" target="_blank" rel="noopener"
 &gt;RingZer0Team.com&lt;/a&gt;. I&amp;rsquo;ve been working through some of these for a wee while now, and with the &lt;a class="link" href="https://www.cybersecuritychallenge.org.nz/" target="_blank" rel="noopener"
 &gt;New Zealand Cyber Security Challenge&lt;/a&gt; coming up again soon, I thought I&amp;rsquo;d get back into some of them.&lt;/p&gt;
&lt;p&gt;Challenge 148 (&amp;ldquo;Sysadmin Linux Level 2&amp;rdquo;) is one of a series of challenges where you&amp;rsquo;re trying to breach the security of a Linux system. I actually finished most of these last year, but I wanted to finish my last two. Of course, to get to the last two stages, you need to use the flags from the &lt;em&gt;previous&lt;/em&gt; stages. So I&amp;rsquo;m revisiting them.&lt;/p&gt;
&lt;p&gt;We start by SSH&amp;rsquo;ing into a particular user account on the ringzer0team server:&lt;/p&gt;
&lt;p&gt;You have mail.
Last login: Thu Apr 27 02:52:40 2017 from &lt;somewhere&gt;
morpheus@forensics:~$&lt;/p&gt;
&lt;p&gt;There&amp;rsquo;s only one file in the home folder, and I can&amp;rsquo;t read it. There&amp;rsquo;s a /home/trinity folder with full read access, but also nothing legible.&lt;/p&gt;
&lt;p&gt;Running ps aux reveals what appears to be Trinity&amp;rsquo;s password:&lt;/p&gt;
&lt;p&gt;root 3241 0.0 0.0 4188 572 ? S Jan14 1:44 /bin/sh /root/backup.sh -u trinity -p Flag-&lt;redacted&gt;&lt;/p&gt;
&lt;p&gt;Aha, and /etc/fstab contains what appears to be The Architect&amp;rsquo;s password, in base64:&lt;/p&gt;
&lt;p&gt;/dev/sr0 /media/cdrom0 udf,iso9660 user,noauto 0 0
/dev/fd0 /media/floppy0 auto rw,user,noauto 0 0
#//TheMAtrix/phone /media/Matrix cifs username=architect,password=$(base64 -d &amp;ldquo;&lt;redacted&gt;&amp;rdquo;),iocharset=utf8,sec=ntlm 0 0&lt;/p&gt;
&lt;p&gt;Great! Now I can carry on to my &lt;em&gt;actual&lt;/em&gt; goal, which was to nail challenge 91 (&amp;ldquo;Sysadmin Linux Level 7&amp;rdquo;)!&lt;/p&gt;</description></item><item><title>RingZer0team CTF - Challenge 57</title><link>https://www.ericlight.com/post/r0-57.html</link><pubDate>Fri, 05 May 2017 00:00:00 +1200</pubDate><guid>https://www.ericlight.com/post/r0-57.html</guid><description>&lt;p&gt;This is a continuation of my series on &lt;a class="link" href="https://www.ringzer0team.com" target="_blank" rel="noopener"
 &gt;RingZer0Team.com&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Challenge 57 (&amp;ldquo;Hash Breaker Reloaded&amp;rdquo;, under the Coding Challenges) is one of a series of challenges where you&amp;rsquo;re simply presented with a hash - you need to return the plaintext value to the page within 3 seconds.&lt;/p&gt;
&lt;p&gt;In contrast to &lt;a class="link" href="https://www.ericlight.com/post/r0-56.html" &gt;Challenge 56&lt;/a&gt;, &lt;strong&gt;this&lt;/strong&gt; challenge also includes a salt:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;You have 3 seconds to break this hash
Send the answer back using https://ringzer0team.com/challenges/57/[clear_text]


----- BEGIN HASH -----
ab9507edbb2501b3c02e47c51af0178d68655980
----- END HASH -----

----- BEGIN SALT -----
c2ac9d8d004b4011d0864e76c7ebaaccfd18464bb8ff66bdbf19a703eb95a944
----- END SALT -----
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The hash looks like another SHA-1, but of course the online hash reversers don&amp;rsquo;t have the &lt;em&gt;now-salted&lt;/em&gt; hash in their rainbow tables. I figured that the challenge was a simple continuation of the previous challenge, so I crossed my fingers and guessed the hash was simply a number (from last time), concatenated with the plain-text salt.&lt;/p&gt;
&lt;p&gt;&amp;hellip; And I was lucky! The below code got me the flag:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#!/usr/bin/python3
from requests import get
from hashlib import sha1
from re import search

url='https://ringzer0team.com/challenges/57'
session=dict(PHPSESSID='&amp;lt;blahblah&amp;gt;')
resp=get(url,cookies=session)
hash=resp.text.split(&amp;quot;-----&amp;quot;)[2].split(&amp;quot;\t&amp;quot;)[2].split(&amp;quot;&amp;lt;&amp;quot;)[0]
salt=resp.text.split(&amp;quot;-----&amp;quot;)[6].split(&amp;quot;\t&amp;quot;)[2].split(&amp;quot;&amp;lt;&amp;quot;)[0]
newhash=''
salt=salt.encode('utf-8')
x=0
while newhash != hash:
		newhash=sha1(str(x).encode('utf-8')+salt).hexdigest()
		print(&amp;quot;%s = %s&amp;quot; % (newhash, x))
		x+=1
	
resp=get(url+'/'+str(x-1),cookies=session)
flag=search(&amp;quot;FLAG-.{24}&amp;quot;,resp.text).group()
print(flag)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;As last time, there&amp;rsquo;s no error handling in that code, so if it runs for more than a few seconds it&amp;rsquo;s probably toast.&lt;/p&gt;</description></item><item><title>RingZer0team CTF - Challenge 56</title><link>https://www.ericlight.com/post/r0-56.html</link><pubDate>Tue, 02 May 2017 00:00:00 +1200</pubDate><guid>https://www.ericlight.com/post/r0-56.html</guid><description>&lt;p&gt;There are a bunch of fantastic Capture The Flag security challenges on &lt;a class="link" href="https://www.ringzer0team.com" target="_blank" rel="noopener"
 &gt;RingZer0Team.com&lt;/a&gt;. I&amp;rsquo;ve been working through some of these for a wee while now, and with the &lt;a class="link" href="https://www.cybersecuritychallenge.org.nz/" target="_blank" rel="noopener"
 &gt;New Zealand Cyber Security Challenge&lt;/a&gt; coming up again soon, I thought I&amp;rsquo;d get back into some of them.&lt;/p&gt;
&lt;p&gt;Challenge 56 (&amp;ldquo;Hash Breaker&amp;rdquo;, under the Coding Challenges) is one of a series of challenges where you&amp;rsquo;re simply presented with a hash - you need to return the plaintext value to the page within 3 seconds.&lt;/p&gt;
&lt;p&gt;Of course, this is impossible to do manually, so it&amp;rsquo;s a programming challenge.&lt;/p&gt;
&lt;p&gt;The hash looks like a simple SHA-1, so I put it into an online hash reverser and discovered it&amp;rsquo;s just a SHA1 hash of a random number. SHA1 is really fast, so this should be simple.&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s how I tackled the problem:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#!python
# It's in Python3, because of reasons
from requests import get
from hashlib import sha1
from re import search
calculated_hash=''
x=0

# Your session cookie needs to go here
session=dict(PHPSESSID='&amp;lt;cookie contents&amp;gt;')

# Load the web page
url='https://ringzer0team.com/challenges/56'
resp=get(url,cookies=session)

# Extract the hash from the page contents
target_hash=resp.text.split(&amp;quot;-----&amp;quot;)[2].split(&amp;quot;\t&amp;quot;)[2].split(&amp;quot;&amp;lt;&amp;quot;)[0]

# Iterate hashes from zero until the calculated hash matches the target hash
while calculated_hash != target_hash:
		calculated_hash=sha1(str(x).encode('utf-8')).hexdigest()
		print(&amp;quot;%s = %s&amp;quot; % (calculated_hash, x))
		x+=1

# If we got here, yay! We found the key. Now submit it back to the site, and print our magic flag
resp=get(url+'/'+str(x-1),cookies=session)
flag=search(&amp;quot;FLAG-.{24}&amp;quot;,resp.text).group()
print(flag)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;There&amp;rsquo;s no error handling in that code, so if it runs for more than a few seconds it&amp;rsquo;s probably toast.&lt;/p&gt;</description></item></channel></rss>