rangearmentRe

Discussion of challenges you have already solved
User avatar
efe
Posts: 45
Joined: Sun Oct 26, 2008 10:28 am
Location: germany

rangearmentRe

Post by efe »

Nice challenge!
It is quite easy if you use the right tools. :D

Code: Select all

import os
f = open("img.png","wb")
for path,dir,files in os.walk("manyfiles"):
	for file in files:		
		f.write(chr(len(open(os.path.join(path,file)).read())))
f.close()
nuvak
Posts: 1
Joined: Mon Oct 27, 2008 9:12 pm

Post by nuvak »

My solution is similar, only a different tool :D

Code: Select all

irb(main):066:0> File.open("../r.png",File::WRONLY|File::TRUNC|File::CREAT){|ofile|
irb(main):067:1* Dir.glob("**/*txt").sort.each{|filename| 
irb(main):068:2* ofile.putc File.size(filename)
irb(main):069:2> }}
User avatar
Yharaskrik
Posts: 31
Joined: Wed Nov 05, 2008 11:44 am
Location: Germany

Post by Yharaskrik »

Nice idea to hide two images... (did you all see the second image?) :D

Solved it by using basic unix tools:

Code: Select all

unzip -l manyfiles.zip | 
  sort -k 4 | 
  perl -n -e "$i++;m/^ +([0-9]+) /;$n=$1;printf """%2.2x""",$n;printf"""\n""" if (($i+1)%32==0)" |
  hex2bin.pl - img.png
Mütze
Posts: 23
Joined: Sun Oct 26, 2008 2:39 pm

Post by Mütze »

Yes, I've seen the second image.

I wrote a bash script, and used 'xxd -r' to convert the output.

Code: Select all

#!/bin/bash

a=0
k=0
for i in manyfiles/*/*/*/*/* ;
do
        s=`ls -al $i | cut -d" " -f5`

        if [ $k -eq 0 ] ;
        then
                printf "%06x:" $a
        fi

        printf " %02x" $s

        k=$((k+1))
        a=$((a+1))

        if [ $k -eq 16 ] ;
        then
                k=0
                echo ""
        fi
done
echo ""
megabreit
Posts: 141
Joined: Sat Jan 03, 2009 3:33 pm

Post by megabreit »

Another funny challenge. This guy knows how to hide things :lol:
I stepped in every trap e.g. decoded the (hidden) image from the filenames to find out it was the wrong one.
Nearly no scripting involved. I used UNIX command line tools like find, wc, sort, sed, awk and a bit perl.
p2p
Posts: 4
Joined: Fri Feb 13, 2009 4:50 pm

Post by p2p »

hah!
finally solved it, after efe said to me that my idea with the length of the strings is correct.
Coding was only a bit C#:
find all files
open files
do something with the content

I was so proud after finding the first image pretty fast...til i took a look at the image-.-
MichaBln
Posts: 18
Joined: Tue Nov 11, 2008 1:55 pm
Location: Berlin, GER

Post by MichaBln »

I used Java and worked directly on the file ...

Code: Select all

	static HashMap<String,Integer> _len = new HashMap<String,Integer>();
	public static void main(String args[]){
		try{
			 ZipFile zipfile = new ZipFile(new File("c:\\hacker\\manyfiles.zip"));
			 Enumeration ez = zipfile.entries();
			 List<String> paths = new ArrayList<String>();
			 while(ez.hasMoreElements()){
				 ZipEntry ze = (ZipEntry) ez.nextElement();
				 paths.add(ze.getName());
				 java.io.InputStream is = zipfile.getInputStream(ze);
				 byte[] buf = new byte[is.available()];
				 is.read(buf);
				 is.close();
				 _len.put(ze.getName(), buf.length);
			 }
			 Collections.sort(paths);
			 FileOutputStream fo = new FileOutputStream("c:\\hacker\\test.png");
			 for(int i=0;i<paths.size();i++)
				 fo.write((byte)(int)_len.get(paths.get(i)));			 
			 fo.close();
		}catch(Exception ex){}
	}
I found the first image too ... this code is just for the 2nd.
Broker
Posts: 26
Joined: Tue Oct 28, 2008 10:53 am
Location: Germany

Post by Broker »

All of you found two images?!
Are you talking about two in summary?

Haven´t you found the third one? :o

1st PNG in Filenames
2nd PNG in Filelength
3rd: After Position 0x00229622 (around the middle of the file) there is an invalid zip-envelope/header, so normal zip-decompression ignores this part. Inside you will find the identical PNG to the 1st PNG with the hint "You are on the right track"

:D
michuber
Posts: 57
Joined: Sun Oct 26, 2008 3:30 pm

Post by michuber »

Broker wrote:3rd: After Position 0x00229622 (around the middle of the file) there is an invalid zip-envelope/header, so normal zip-decompression ignores this part. Inside you will find the identical PNG to the 1st PNG with the hint "You are on the right track"
No, there are only two PNGs. The "central directory" of the zip file starts at this position, of course you can decode both images from it.
Broker
Posts: 26
Joined: Tue Oct 28, 2008 10:53 am
Location: Germany

Post by Broker »

Ahh i see. Thanks for the Info.
gfoot
Posts: 269
Joined: Wed Sep 05, 2007 11:34 pm
Location: Brighton, UK

Post by gfoot »

megabreit: By the time you've used "a bit" of Perl, you might as well have done the whole thing in Perl. :)

efe: did you know about os.stat(filename).st_size?
User avatar
efe
Posts: 45
Joined: Sun Oct 26, 2008 10:28 am
Location: germany

Post by efe »

gfoot: using the stat system call would be of course more efficient ...

...and the code gets even smaller:

Code: Select all

import os
f = open("img.png","wb")
for path,dir,files in os.walk("manyfiles"):
   for file in files:      
      f.write(chr(os.stat(os.path.join(path, file)).st_size))
f.close() 
cyberwoozle
Posts: 60
Joined: Fri Nov 07, 2008 10:43 am
Location: Germany

Post by cyberwoozle »

I've created a text file via

Code: Select all

dir /s > manyfiles.txt
Then i wrote this small program:

Code: Select all

f_out = open('c:\manyfilesout-2.png', 'w')
for i in lines:
    if i[17:26] == "Datei(en)":
        ## print int(i[38:41])
        f_out.write (chr(int(i[38:41])))
f_out.close()
What i don't understand is, that whenever 0x0A should be written to the out-file, the program writes 0x0A 0x0D instead.
If i print the results to the screen (using print int(i[38:41]) instead of f_out.write (chr(int(i[38:41]))) ), it shows the results correctly.

So in the end i had to use a Hex-editor and search all 0A0Ds and replace them with 0As.

I have to admit, that i'm not a great programmer ( i started programming in Python when i joined hacker.org in november), so possibly this question is a little stupid, but i have no explanation for this behaviour. Can anybody give me a tip?

Cheers ...
gfoot
Posts: 269
Joined: Wed Sep 05, 2007 11:34 pm
Location: Brighton, UK

Post by gfoot »

Different systems have different conventions about line endings in text files. On Windows in particular, when you write 0x0A it will automatically also write a 0x0D because that's the convention there, for some odd reason. On Unix it won't do that. On Macs I think it will just write 0x0D, without the 0x0A you actually asked for.

In any case, to be portable you should open the file in binary mode, by adding a "b" to the open flags (e.g. "wb"), which disables this behaviour.
cyberwoozle
Posts: 60
Joined: Fri Nov 07, 2008 10:43 am
Location: Germany

Post by cyberwoozle »

Cool, this really works! Thank you!
Post Reply