- Prison Code Breaker Diary -

=> aka: Nhật Kí Code Tù

Categories

Showing posts with label Linux. Show all posts

#!/bin/bash
#Valentin Heinitz, www.heinitz-it.de, 2008-11-13
#Reader for MS Windows 3.1 Ini-files
#Usage: inireader.sh
# e.g.: inireader.sh win.ini ERRORS DISABLE
# would return value "no" from the section of win.ini
#[ERRORS]
#DISABLE=no
INIFILE=$1
SECTION=$2
ITEM=$3
cat $INIFILE | sed -n /^\[$SECTION\]/,/^\[.*\]/p | grep "^[:space:]*$ITEM[:space:]*=" | sed s/.*=[:space:]*//

I got it from here.

Linux bash shell provides 2 types of test:
+ ( -ot ) : is other than
+ ( -nt ) : is newer than


#!/bin/sh

if [ "$file1" -nt "$file2" ]
then
    echo -e "$file1 is newer than $file2"
else
    echo -e "$file1 is older than $file2"
fi

I write this bash script to automate the process of creating Linux libraries in C/C++

#!/bin/bash

clear

echo -e "##########################################"
echo -e "#     LIBRARY AUTO-CREATOR by [JaPh]     #"
echo -e "#========================================#"
echo -e "Usage: `basename $0` lib_name type path   "
echo -e "Example: "
echo -e " + creating libraries from hello.c in current directory"
echo -e " `basename $0` hello C . "
echo -e " + creating libraries from bye.cpp to '/opt/lib' directory"
echo -e "   `basename $0` bye C++ /opt/lib"
echo -e "Feel free to contact, pete.houston.17187@gmail.com\n"

ARG=3

if [ "$#" -ne "$ARG" ]
then
 echo -e "[?] wrong input arguments!"
 exit
fi

libname=lib"$1"

if [ "$2" == "C" ]
then
 filename="$1.c"
 compiler="gcc"
elif [ "$2" == "C++" ]
then
 filename="$1.cpp"
 compiler="g++"
else
 echo -e "[?] unknown filetype"
 exit
fi

echo -e "< Static Library: $libname.a >"
command="$compiler -Wall -c $filename"
echo -e "\$ $command"
if [ !`$command` ]
then
 echo -e ".created: $1.o"
else
 echo -e ".[?] cannot create object $1.o"
 exit
fi

echo -e "\$ ar -cvq $libname.a $1.o"
ar -cvq $libname.a $1.o
echo -e ".created: $libname.a"
echo -e "< Static Library '$libname.a' created ! >"

rm -f $1.o
echo -e "< Shared Object Library: $libname.so.1.0 >"
command="$compiler -Wall -fPIC -c $1.c"
echo -e "\$ $command"
if [ !`$command` ]
then
 echo -e ".created: $1.o"
else
 echo -e ".[?] cannot create object $1.o"
 exit
fi

command="$compiler -shared -Wl,-soname,$libname.so.1 -o $libname.so.1.0 $1.o"
echo -e "\$ $command"
if [ !`$command` ]
then
 echo -e ".created: $libname.so.1.0"
else
 echo -e ".[?] cannot create shared object $libname.so.1.0"
 exit
fi

ln -sf $libname.so.1.0 $libname.so
ln -sf $libname.so.1.0 $libname.so.1

echo -e "< Shared Object Library '$libname.so.1.0' created ! >"

if [ "$3" != "." ]
then
 mv $libname.* "$3"
 echo -e "[!] All files moved to $3"
fi


STATIC LIBRARY (.a)

+ Compile

$ gcc -Wall -c *.c
+ Create library
$ ar -cvq libtest *.o
+ List files in library
$ ar -t libtest.a
+ Linking with library
$ gcc -o executable-name prog.c libtest.a
$ gcc -o executable-name prog.c -L/path/to/library-dir -ltest


Shared Object: DYNAMICALLY LINKED LIBRARY

+ Compile object
$ gcc -Wall -fPIC -c *.c
+ Create shared object
$ gcc -shared -Wl,-soname,libtest.so.1 -o libtest.so.1.0 -o *.o
+ Move library to destination
$ mv libtest.so.1.0 /path/to/lib-dir
+ Allow naming convention like -ltest
$ ln -sf /path/to/lib-dir/libtest.so.1.0 /path/to/lib-dir/libtest.so
+ Allow run-time binding to work
$ ln -sf /path/to/lib-dir/libtest.so.1.0 /path/to/lib-dir/libtest.so.1
+ Testing executable file dependencies
$ ldd executable-file


Reference: Yo-Linux

libcurl - the multiprotocol file transfer library

libcurl is a free and easy-to-use client-side URL transfer library, supporting FTP, FTPS, HTTP, HTTPS, SCP, SFTP, TFTP, TELNET, DICT, LDAP, LDAPS, FILE, IMAP, SMTP, POP3 and RTSP. libcurl supports SSL certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies, cookies, user+password authentication (Basic, Digest, NTLM, Negotiate, Kerberos4), file transfer resume, http proxy tunneling and more!

libcurl is highly portable, it builds and works identically on numerous platforms, including Solaris, NetBSD, FreeBSD, OpenBSD, Darwin, HPUX, IRIX, AIX, Tru64, Linux, UnixWare, HURD, Windows, Amiga, OS/2, BeOs, Mac OS X, Ultrix, QNX, OpenVMS, RISC OS, Novell NetWare, DOS and more...

libcurl is free, thread-safe, IPv6 compatible, feature rich, well supported, fast, thoroughly documented and is already used by many known, big and successful companies and numerous applications.

Homepage: http://curl.haxx.se/libcurl/

First, download and install cURL library package.
Then, use the utility 'curl-config' to get the compile options need for cURL program

$ curl-config --cflags
$ curl-config --libs

This is a simple program that retrieve a web page:

#include <stdio.h>
#include <curl/curl.h>
int main()
{
 CURL *curl;
 CURLcode res;
 
 curl = curl_easy_init();
 if(curl) {
  curl_easy_setopt(curl, CURLOPT_URL, "xjaphx.blogspot.com");
  res = curl_easy_perform(curl);
  
  curl_easy_cleanup(curl);
 }
 return 0;
}

Try to compile with this option:

$ gcc -o curl_simple curl_simple.c `curl-config --libs`
$ ./curl_simple

The header is needed in program `#include `, you can find its location by this


$ whereis curl
$ whereis curl.h

Probably, it will be /usr/bin/curl /usr/include/curl
While compile, you need to specify the linking library, that's why I set option `curl-config --libs`.
If you run this command alone


$ curl-config --libs
-lcurl
That's the result. Instead, you can compile like this

$ gcc -o curl_simple curl_simple.c -lcurl

Which gives the same result.

NateOn is the instant messenger created by SK Telecom, for Koreans.
However, it does supports Windows only as main platform.
I've just found some projects that provides a way to communicate with NateOn under Linux.

1. For Mac / Linux (Gnome users):
- JateOn, written in Java (Swing, SWT required): http://jateon.kfmes.com/viewforum.php?f=4
It's still being developed.
- NateOn plugin for Pidgin: http://nateon.haz3.com
I don't think it is under development anymore....

2. For Linux (KDE users): this is the best choice
- NateOn Linux (current version 1.0 beta): http://nateonweb.nate.com/download/messenger/linux/
It's best if you are using Fedora, Gentoo or Ubuntu because the installation package is done, just one click and run. Other distros might need to download source and compile.

3. Using WineHQ to emulate:
- Some notes on experiment can give you a hint. You might want to give it a try: http://appdb.winehq.org/objectManager.php?sClass=version&iId=7524&iTestingId=11299

If you know any other, please notice me!

This is an amazing download manager, which is an add-on of Firefox. Not saying it's the best, however, if you are using Linux and looking for a good download manager, DownThemAll owns !!!

Homepage: http://downthemall.net/
Download: https://addons.mozilla.org/en-US/firefox/addon/201

I gave it a try and now it becomes my favorite one.
It supports downloads from almost all common network protocols, can resume downloads (also depending on the servers' allowance), just one click and download, especially, it can be used to download from various hosting sites like: rapidshare.com, megaupload.com, ....

Compare to others, I think I love DTA the most !

It's possible. Yes, it is!

NOTE: this guide is for education purposes only, not promoting for illegal actions

Requirements:
1. Crossover Linux Professional 7.0: get it here: Download

2. Installation package for Ms Office 2007.

How-to:

1. From menu, choose CrossOver -> Install Windows Software. Pick Microsoft Office 2007, locate the setup.exe file, then install it as in Windows.

2. After all installation done, we need to crack it though.
a. Get this file: Proof.XML
b. Replace the old one located under:

/home/[YOUR_USER_NAME]/.cxoffice/MSOffice/drive_c/Program Files/Common Files/Microsoft Shared/OFFICE12/Office Setup Controller/Proof.en
c. From CrossOver menu -> Run a Windows Command, type: regedit
d. Find the key: HKLM\Software\Microsoft\Office\12.0\Registration\DigitalProductID, and delete it.
e. Close all CrossOver-related program.
d. Under main menu: Applications, you can see Windows Application menu, and enjoy !


Enjoy !

It's really itchy to have menu list cover half of your screen, they're way too biggggg!!!
I've googled to find the solution but it's like impossible @@!
Finally, I got the answer. This is how-to make it better look for you.

Choose a theme to use in order to edit that theme, example, I use 'Is Ora Smooth'.
Then I locate to its settings at: /usr/share/themes/Is Ora Smooth/gtk-2.0/gtkrc
Run gEdit or any text editor under root permission to edit this file.

Add this option into the file:

gtk-icon-sizes = "panel-menu=16,16"

I'm not sure if you want to make it smaller but the size is often like 16, 24 or 32.
Choose the one that best fits for you.
Logout and apply that theme, you'll see how beautiful it is!

Here's the trick, using the -o, and L option we can search for what we need to print out

ps -opid -A

The End!

Oh yes, it took me time to search for this.
Here's the trick:


ps -o"%C" -p #PID

or simplified version

ps -opcpu -p #PID

The End :D

Menu Preferences | Appearances

  • Theme | Customize
    1. Controls | Is Ora Smooth
    2. Window Border | evil_mac - Download
    3. Icons | Ultimate Gnome - Download
    4. Pointer | Wonderland
  • Fonts
    1. Application Font | Segoe UI | 11
    2. Document Font | Segoe UI | 11
    3. Desktop Font | Trebuchet MS Bold | 9
    4. Window Title Font | Segoe UI | 11
    5. Fixed Width Font | Monospace | 10
    6. Rendering | Best Shapes
    7. Details | Resolution
    • Resolution | 75 dots per inch
    • Smoothing | Grayscale
    • Hinting | Medium
    • Subpixel Order | RGB
  • Background - Download Corlorful Pack

Programming .NET is one of the first thing I've learned myself long ago, but only available in Windows Operating System.
Somehow, the Mono Project has made .NET Framework become a cross-platform environment that you can freely programming .NET for Windows, Linux, MacOS...in that system directly. Also, you can write a .NET program for Linux under Windows and vice-versa. It's really a great achievement that Mono Project has reached. I expect that Mono Project will achieve more impressive goals with .NET technology in the future as it develops.
I write this guide as a journal in programming .NET under Linux environment by using Mono Project.
You may take this as a reference for Gtk#.

1 - Documentation and Reference:
Here the list that I read and reference from:
Gtk# Tutorial Page by Mono
Mono Documentation Library (equivalent to MSDN)
Mono: A Developer's Notebook (Edd Dumbill, Niel M. Bornstein) - A great book, worth to buy for two reasons:
+ It's the only book on Mono up to this time.
+ It's written as a developer's journal style, so it's really easy to catch the authors' mind concepts.

2 - Programming Gtk# Journal

Lesson 1: Say Hello
Lesson 2: Hello Gtk# (using Form)
Lesson 3: MonoDevelop IDE vs. manual text coding w/ commands. (to be updated...)


Feel free to comment!
Have fun!

Download Project

We do the same thing with Lesson 1 but this time we use form for better GUI.
This is the source code, self-explained fully-commented.



using System;
using Gtk;

public class Lesson_2
{

public static void Main() {

Application.Init();

// create a window
Window window = new Window("Lesson 2: Say hello with Gtk# Form");
window.Resize(400, 40);

// create a label
Label label = new Label("Hello Gtk# .NET");
// add label to the form
window.Add(label);
// show form and its widgets
window.ShowAll();

Application.Run();
}
}


Build and run, this is result:


Have fun!

Download Project: Lesson 1 - Say Hello Gtk#

First, open MonoDevelop and create a new empty project. Then, add an empty class file into project. Copy this code below to the file:


using System;

public class Lesson_1 {

public static void Main() {
Console.WriteLine("Lesson 1: Hello Gtk#! It's so wonderful!");
}
}

If you already know C#, you, hence, know what it means.

Now click on the menu Build -> Build Solution or F8.
Click menu Run -> Run or Ctrl+F5.
You will have result like this:

The result is shown under the Application Output textbox.

However, if you want to compile a single C# file or a C# project manually, then do this.

Open the terminal:

terminal> mcs -pkg:gtk-sharp-2.0 Main.cs

A file named Main.exe will be generated. In order to run this file you have to use mono utility:

terminal> mono Main.exe

The result will show up exactly how it is while using MonoDevelop.

Have fun!

Use xrandr utility to change the screen resolution.
Example, if I want to change my screen resolution into 1280x800 (60 Hz) I will type


terminal> xrandr -s 1280x800

Have fun!

Today, we will learn a new widget control, GtkEntry, a text editor. It's a text box that users can input text inside.
Reference GtkEntry

I'm not gonna explain each properties and methods in details anymore. However, to practice directly is the better way of learning it since you've already familiar with Gtk+ programming.

Practice 1: A simple one, a label will show up everything you type in the entry box when clicking a button.



/*
* @author [JaPh]
* @date 30 August, 2009
* @file GtkEntry_01.c
* @site http://xjaphx.blogspot.com/
*/

#include <gtk/gtk.h>
#include <glib.h>
typedef struct _STORE {
GtkLabel *label;
GtkEntry *entry;
} STORE;

void
btn_get_clicked_event( GtkButton *btn_get, STORE *data )
{
gtk_label_set_text( data->label, gtk_entry_get_text(data->entry));
}

int
main( int argc, char *argv[] )
{
GtkWidget *window;
GtkWidget *label;
GtkWidget *entry;
GtkWidget *btn_get;
GtkWidget *vbox;
STORE *data;

gtk_init( &argc, &argv );

window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
gtk_window_set_title( GTK_WINDOW(window), "[JaPh]Lesson 13: GtkEntry" );
gtk_window_set_default_size( GTK_WINDOW(window), 100, 100 );

label = gtk_label_new("Type anything to entry below: ");
btn_get = gtk_button_new_with_mnemonic("_Get");
entry = gtk_entry_new_with_max_length( 128 );

vbox = gtk_vbox_new( TRUE, 5 );

gtk_box_pack_start( GTK_BOX(vbox), label, TRUE, TRUE, 5);
gtk_box_pack_start( GTK_BOX(vbox), entry, TRUE, TRUE, 5);
gtk_box_pack_start( GTK_BOX(vbox), btn_get, TRUE, TRUE, 5);

data = (STORE *) g_malloc( sizeof (STORE) );
data->label = GTK_LABEL(label);
data->entry = GTK_ENTRY(entry);

gtk_container_add( GTK_CONTAINER(window), vbox);

g_signal_connect( G_OBJECT(window), "destroy", G_CALLBACK( gtk_main_quit ), NULL );
g_signal_connect( GTK_BUTTON(btn_get), "clicked",
G_CALLBACK( btn_get_clicked_event ), data );


gtk_widget_show_all( window );
gtk_main();
g_free( data );
return 0;
}

Practice 2: How about a login dialog !




/*
* @author [JaPh]
* @date 30 August, 2009
* @file GtkEntry_02.c
* @site http://xjaphx.blogspot.com/
*/

#include <gtk/gtk.h>
#include <string.h>
#include <glib.h>

typedef struct _DATA {
GtkWidget *widget;
struct _DATA *next;
} DATA;

const char *username = "[JaPh]";
const char *password = "Lesson 14";

void
MessageBox( GtkMessageType type, const char *title, const char *message, const char* details )
{
int res;
GtkWidget *message_box;
message_box = gtk_message_dialog_new( NULL,
GTK_DIALOG_DESTROY_WITH_PARENT,
type, GTK_BUTTONS_OK,
message );

gtk_window_set_title( GTK_WINDOW(message_box), "[JaPh]Lesson 14: GtkEntry" );
gtk_message_dialog_format_secondary_text( GTK_MESSAGE_DIALOG(message_box), details );

res = gtk_dialog_run( GTK_DIALOG(message_box));
if( res == GTK_RESPONSE_OK ) {
gtk_widget_destroy( message_box );
}
}

void
btn_login_clicked_event( GtkButton *btn_login, DATA *data )
{
if( !strcmp( username, gtk_entry_get_text( data->widget ) ) &&
!strcmp( password, gtk_entry_get_text( data->next->widget )) )
{
MessageBox( GTK_MESSAGE_INFO, "Congratulations!", "Correct!",
"Username and password are correct." );
} else {
MessageBox( GTK_MESSAGE_ERROR, "Fail ", "Incorrect",
"Username and password are incorrect." );
}
}


int
main( int argc, char *argv[] )
{
GtkWidget *window;
GtkWidget *vbox;
GtkWidget *hbox_user, *hbox_pass, *hbox_button;
GtkWidget *lbl_user, *lbl_pass;
GtkWidget *txt_user, *txt_pass;
GtkWidget *btn_login, *btn_exit;
DATA *data;

gtk_init( &argc, &argv );

window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
gtk_window_set_title( GTK_WINDOW(window), "[JaPh]Lesson 14: GtkEntry" );
gtk_window_set_default_size( GTK_WINDOW(window), 100, 100 );

lbl_user = gtk_label_new("Username: ");
txt_user = gtk_entry_new();
hbox_user = gtk_hbox_new(TRUE, 5);
gtk_box_pack_start( GTK_BOX(hbox_user), lbl_user, TRUE,TRUE, 5);
gtk_box_pack_start( GTK_BOX(hbox_user), txt_user, TRUE,TRUE, 5);

lbl_pass = gtk_label_new("Password: ");
txt_pass = gtk_entry_new();
/* set invisible character */
gtk_entry_set_invisible_char( GTK_ENTRY(txt_pass), '*' );
/* activate the invisibility mode */
gtk_entry_set_visibility( GTK_ENTRY( txt_pass ), FALSE );
hbox_pass = gtk_hbox_new( TRUE, 5);
gtk_box_pack_start( GTK_BOX(hbox_pass), lbl_pass, TRUE, TRUE, 5);
gtk_box_pack_start( GTK_BOX(hbox_pass), txt_pass, TRUE, TRUE, 5);

btn_login = gtk_button_new_with_mnemonic("_Login");
btn_exit = gtk_button_new_with_mnemonic("E_xit");
hbox_button = gtk_hbox_new( TRUE, 5);
gtk_box_pack_start( GTK_BOX(hbox_button), btn_login, FALSE, TRUE, 20);
gtk_box_pack_start( GTK_BOX(hbox_button), btn_exit, FALSE, TRUE, 20);

vbox = gtk_vbox_new( TRUE, 0);
gtk_box_pack_start( GTK_BOX(vbox), hbox_user, TRUE, TRUE, 0);
gtk_box_pack_start( GTK_BOX(vbox), hbox_pass, TRUE, TRUE, 0);
gtk_box_pack_start( GTK_BOX(vbox), hbox_button, TRUE, TRUE, 0);

data = (DATA *) g_malloc( sizeof( DATA ));
data->widget = txt_user;
data->next = (DATA *) g_malloc( sizeof( DATA ));
data->next->widget = txt_pass;
data->next->next = NULL;

gtk_container_add( GTK_CONTAINER(window), vbox);

g_signal_connect( G_OBJECT(window), "destroy",
G_CALLBACK( gtk_main_quit ), NULL );

g_signal_connect( GTK_BUTTON(btn_login), "clicked",
G_CALLBACK( btn_login_clicked_event ), data );
g_signal_connect( G_OBJECT(btn_exit), "clicked",
G_CALLBACK( gtk_main_quit ), NULL );

gtk_widget_show_all( window );
gtk_main();
g_free(data);
return 0;
}

Well, not much to say but I'm going to create several special sessions next on Gtk+ programming. Make sure you understand all the basics of Gtk+.

Have fun!@

[ Crackme Info ]
Difficulty: 1 - Very easy, for newbies
Platform: Unix/linux etc.
Language: Assembler
Refer: click here
Click to Download

Load into IDA, we have the main program


.text:08048085 mov ebx, 1 ; fd
.text:0804808A mov ecx, offset aPassword ; "\nPassword : "
.text:0804808F mov edx, 0Dh ; len
.text:08048094 int 80h ; LINUX - sys_write
.text:08048096 mov edx, 100h ; len
.text:0804809B mov ecx, offset asc_804911B ; " "
.text:080480A0 mov ebx, 0 ; fd
.text:080480A5 mov eax, 3
.text:080480AA int 80h ; LINUX - sys_read
.text:080480AC mov esi, offset aQtbxctu ; "QTBXCTU"
.text:080480B1 mov edi, esi
.text:080480B3 xor ebx, ebx
.text:080480B5 cld
.text:080480B6
.text:080480B6 loc_80480B6: ; CODE XREF: start+43j
.text:080480B6 lodsb
.text:080480B7 xor al, 21h
.text:080480B9 stosb
.text:080480BA inc ebx
.text:080480BB cmp ebx, 7
.text:080480C1 jz short loc_80480C5
.text:080480C3 loop loc_80480B6
.text:080480C5
.text:080480C5 loc_80480C5: ; CODE XREF: start+41j
.text:080480C5 mov esi, offset asc_804911B ; " "
.text:080480CA mov edi, offset aQtbxctu ; "QTBXCTU"
.text:080480CF mov ecx, 7
.text:080480D4 cld
.text:080480D5 repe cmpsb
.text:080480D7 jnz short loc_80480EF
.text:080480D9 mov eax, 4
.text:080480DE mov ebx, 1 ; status
.text:080480E3 mov ecx, offset unk_8049105 ; addr
.text:080480E8 mov edx, 16h ; len
.text:080480ED int 80h ; LINUX - sys_write
.text:080480EF
.text:080480EF loc_80480EF: ; CODE XREF: start+57j
.text:080480EF mov eax, 1
.text:080480F4 int 80h ; LINUX - sys_exit
.text:080480F4 start endp
.text:080480F4
.text:080480F4 _text ends
.text:080480F4

Each bytes of our input password is encrypted:

.text:080480B6 loc_80480B6: ; CODE XREF: start+43j
.text:080480B6 lodsb
.text:080480B7 xor al, 21h
.text:080480B9 stosb
.text:080480BA inc ebx
.text:080480BB cmp ebx, 7
.text:080480C1 jz short loc_80480C5
.text:080480C3 loop loc_80480B6

So, the real password can be found if we decrypt the string "QTBXCTU".
The encryption is simple, each byte is XORed w/ 0x21.
Then, we also use XORed w/ 0x21 to decrypt it.
Here a little perl script I wrote to decrypt.

#!/usr/bin/perl
my $cipher_txt = "QTBXCTU";
my $plain_txt;

my @arr = unpack("C*", $cipher_txt);
foreach my $c (@arr) {
$plain_txt .= chr( $c ^ 0x21 );
}

print $plain_txt, "\n";


Have fun!@

This is my little video guide through the wargame of SmashTheStack.Org

Wargame: SmashTheStack.Org | IO | Level 5
Creator: [JaPh]
Video: [ OGV | Length: 18.08 min | 72.1 MB | Super High Quality ]
Download: Rapidshare
Password: [japh]

Have fun!@

I use these crackmes as a practice for reversing and debugging skills. However, any time I solve a crackme, I make a post as a guide for those who have the same interest as me and have troubles with them.
These crackmes are dedicated to run under Linux environment only, not Windows.
I collect these crackmes on crackmes.de site, so I can visit that site and check out for information.
Hope this would be helpful to someone.

[Level: EASIEST, FOR NEWBIES ONLY]

Guide to crack "Easy Linux Crackme" by lord
Solve cyrex's Linux CrackMe
Solve cyrex's Linux Crackme02
Solve dynsym's Crackme
Solve intsig's Easymath
Solve Qnix's qcrk5
Solve cli3nt's mycrk
Solve lord's Easy Crackme 2

[ to be updated...]

Have fun!@