تبلیغات :
آکوستیک ، فوم شانه تخم مرغی، صداگیر ماینر ، یونولیت
دستگاه جوجه کشی حرفه ای
فروش آنلاین لباس کودک
خرید فالوور ایرانی
خرید فالوور اینستاگرام
خرید ممبر تلگرام

[ + افزودن آگهی متنی جدید ]




صفحه 16 از 17 اولاول ... 6121314151617 آخرآخر
نمايش نتايج 151 به 160 از 163

نام تاپيک: آموزش کرک و قفل شکنی ( انگلیسی ) از بهترین کرکرهای روس و ...

  1. #151
    پروفشنال Morteza_SOS's Avatar
    تاريخ عضويت
    Apr 2006
    پست ها
    577

    پيش فرض

    Level : beginner

    This is a small, and by no means complete, digestion of some crypto techniques.
    Featuring :
    - Transposition
    - Substitution
    - Frequency analysis
    - Le Chiffre Indéchiffrable
    - Charles Babbage and Vigenére
    - Playfair
    - ADFGVX crypto




    Transposition

    One method of crypting a text is transposition.
    One simple traspose is to write out the message on two rows.
    Letters 1,3, 5 and so on, you write on the first row.
    Letters 2, 4, 6 etc. you write on the second row.
    The message:
    Your secret is your prisoner, let it go and you become its prisoner.

    Row 1:
    Yusceiyupioelyyonyueoeypioi

    Row 2:
    orertsorrsnreigadobcmisrsnr

    Crypted text:
    Yusceiyupioelyyonyueoeypioiorertsorrsnreigadobcmis rsnr


    Substitution

    Another method is substitution where you substitute one letter with another letter.
    Code
    ====
    A code substitute a word or group of letter.

    Monoalphabetic substitution
    =======================
    One variant is the Caesar roll. This is based on crypto alphabet that's shifted a number
    of steps relative the clear text alphabet. It's common in cryptography to write out the
    clear text in lowercase letter and the crypted text in uppercase letter.

    Clear alphabet:
    abcdefghijklmnopqrstuvwxyz

    Crypto alphabet:
    DEFGHIJKLMNOPQRSTUVWXYZABC (here with a three letter right rotation)

    Clear text:
    veni, vidi vici

    Crypto text:
    YHQL, YLGL, YLFL

    To crypt a text, you write out the crypto alphabet under the clear alphabet.
    Then you take the letter from the text, here starting with "v", and go to the
    column where v is in the clear alphabet.
    Look in the same column in the crypto alphabet to get the letter to substitute with.
    Here v is substituted with Y. Repeat this for all letters in the text.

    As you may see, this is not a very strong protection. With a computer it's easy to
    try all possible shifts, where each shift can be regarded as a key to the crypto.

    Monoalphabetic substitution with key
    ====================================
    If you choose a more general algorithm where the clear alphabet can be reordered in any possible way,
    you get 400 000 000 000 000 000 000 000 000 possible keys to choose from. If the enemy gets hold of
    the crypted text and he knows the algorithm, he still have to test all keys to decrypt the message.
    If he test one key per second, he approximately would need the time equal the age of
    universe multiplied with 10e9.

    Clear alphabet:
    abcdefghijklmnopqrstuvwxyz

    Crypto alphabet:
    DJKTUVCWNOLPAEGFHIQRXYMSZB ("random" order)

    Clear text:
    ettu, brute?

    Crypto text:
    URRX, JIXRU?

    It can be shown with mathematical proof, that if you use a random key as long as the text you want to crypt,
    the crypted text CAN NOT be decrypted if you don't know the key. In any crypto a weak spot is repetitions
    that occur if you use a to short key. Another thing to remember is that you can't use the same key twice,
    and you must use a really random key. If you use the key more then once, there's methods to break the crypto.

    A variant to this, but with a less number of keys, is to use a key or key phrase. Instead of a random alphabet
    you take a key or a key phrase, for example "Julius Ceasar". Remove all spaces and duplicate letters and use
    the rest, JULISCAER, as beginning of the crypto alphabet. The rest of the alphabet is just a shift beginning
    where the keyword ends and with the letters in the keyword removed from the alphabet.

    Clear alphabet:
    abcdefghijklmnopqrstuvwxyz

    Crypto alphabet:
    JULISCAERTVWXYZBDFGHKMNOPQ

    This can also be rotated a number of steps to.
    Crypto alphabet:
    CAERTVWXYZBDFGHKMNOPQJULIS

    A good thing about this is that it is easy to remember the key word or key phrase. The simplicity in combination
    with the strength made this the common method to crypt a text the first thousand years a.c.

    Anyone interested in cracking a monoalphabetic text can look at the mono crackme in the crackme's.


    But there is ways to break this crypto, the Arabs was the first ones out.


    Frequency analysis

    The oldest known description, by an Arab, to break a monoalphabetic crypto is from 800 a.c.
    The trick is that in any given language there's letters that's used more frequently.
    If you know the letter frequency for a language, you take the letters frequency in the crypted
    text and substitute it with the one that have about the same frequency for that language.
    It's relatively easy to make a qualified guess what letter it is.
    The same rules can be applied on one, two, three or more, letter words.

    As you are a cracker, it's easy to write a small app to analyse some text files on your computer.
    What kind of text you analyse of course affects the result of the letter frequency. If you for example
    analyze a sorce code file, you get a funny letter and word distribution. If it's a *.asm file you get a
    lot of three letter words like: eax,ebx,ecx...:-).


    Le Chiffre Indéchiffrable

    For many centuries the monoalphabetic substitution crypto was the prevailing method to write a secret text.
    But after the Arabs invention of the frequency analyze, this method was no longer a safe one to use.
    The original idea for this new crypto came from a man named Leon Battista Alberti, born 1404.
    His idea was use two or more crypto alphabet and switch between them.

    Clear alphabet:
    abcdefghijklmnopqrstuvwxyz

    Crypto alphabet 1:
    FZBVKIXAYMEPLSDHJORGNQCUTW

    Crypto alphabet 2:
    GOXBFWTHQILAZPJDESYVCRKUHN

    If we crypt the word "hello" we use the first alphabet for h, that become A.
    For the second letter e we use the second alphabet, e becomes F, and so on.
    With this method hello becomes AFPAD.

    A man named Blaise de Vigenére, born 1523, developed this idea further.
    Instead of using two or three alphabet, he used 26 (for a-z for English).
    Although he based his work on ideas of previous thinkers, this method is known as the Vigenére crypto.
    The use of more than one crypto alphabet gives this type of crypto the name polyalphabetic crypto.

    The first step to use this is to write out a Vigenére table. This is done by writing down a clear alphabet
    followed by 26 crypto alphabets, each one rotated on step in relation to the previous one.

    abcdefghijklmnopqrstuvwxyz1 BCDEFGHIJKLMNOPQRSTUVWXYZA2 CDEFGHIJKLMNOPQRSTUVWXYZAB3 DEFGHIJKLMNOPQRSTUVWXYZABC4 EFGHIJKLMNOPQRSTUVWXYZABCD5 FGHIJKLMNOPQRSTUVWXYZABCDE6 GHIJKLMNOPQRSTUVWXYZABCDEF7 HIJKLMNOPQRSTUVWXYZABCDEFG8 IJKLMNOPQRSTUVWXYZABCDEFGH9 JKLMNOPQRSTUVWXYZABCDEFGHI10 KLMNOPQRSTUVWXYZABCDEFGHIJ11 LMNOPQRSTUVWXYZABCDEFGHIJK12 MNOPQRSTUVWXYZABCDEFGHIJKL13 NOPQRSTUVWXYZABCDEFGHIJKLM14 OPQRSTUVWXYZABCDEFGHIJKLMN15 PQRSTUVWXYZABCDEFGHIJKLMNO16 QRSTUVWXYZABCDEFGHIJKLMNOP17 RSTUVWXYZABCDEFGHIJKLMNOPQ18 STUVWXYZABCDEFGHIJKLMNOPQR19 TUVWXYZABCDEFGHIJKLMNOPQRS20 UVWXYZABCDEFGHIJKLMNOPQRST21 VWXYZABCDEFGHIJKLMNOPQRSTU22 WXYZABCDEFGHIJKLMNOPQRSTUV23 XYZABCDEFGHIJKLMNOPQRSTUVW24 YZABCDEFGHIJKLMNOPQRSTUVWX25 ZABCDEFGHIJKLMNOPQRSTUVWXY26 ABCDEFGHIJKLMNOPQRSTUVWXYZ



    The first row is a crypto alphabet with a Caesar roll, a rotation of one step.
    The second one have a two step rotation and so on.
    To use it, you use a new row for each letter you crypt.
    To decrypt it the user must know which row to use for which letter.
    You maybe use row 5 for the first letter, row 14 for the second, row 21 for the third and so on.

    To decrypt the text the receiver must know which row shifts to use.
    One way to do this is to use a key word.
    To crypt the message "Begin attack at sundown" and the key GREEN we do like this.

    Write out the key word above the message over and over, so each letter in the message
    is linked to a letter in the key word.


    GREENGREENGREENGREENbeginattackatsundown

    Then you create the crypto text like this:
    Crypt the letter b by taking the letter in the key word above, here it is G.
    This letter is the index to a row in the Vigenére table.
    The row beginning with G, row 6, is the crypto alphabet to use for
    the first letter b. In the row for the clear alphabet, go to the column
    for the letter b. To find the substitution letter, follow this column down
    to row 6, here you find the letter H to substitute for b.
    Repeat this procedure for the letter e. The key letter above e is R which gives
    us the row that start with R, row number 17. In the clear alphabet, go to the column
    for the letter e in the clear alphabet, follow this column down to row 17 to get the substitution letter V.

    Repeat this for each letter in the message.

    Each letter in the keyword gives us a different crypto alphabet to use.
    The number of letters in the key word gives us the number of rows to use in the
    Vigenére table. In this example we use four rows, G, R, E and N (E is doubled here).

    The message "beginattackatsundown" crypted with the keyword GREEN comes out as:
    HVKMAGKXEPQRXWHTUSAA

    With a longer keyword, or a key sentence, you add more rows from the table you make the crypto more
    difficult to break. The frequency analysis, described above, has no effect on this kind of crypto.
    If you have a word with at double letter, like attack above, the first t becomes K and the second becomes X.
    If you do a frequency analysis of this, there's no way to tell that this is the letter t.
    Another strength is the enormous number of keys you can use. Any word in the book can be used,
    you even can make up you own words. It's just not possible to try all possible combinations.
    The work by Vigenéres was published in Tracicté des Chiffres 1586 but did not come to common use
    until 200 years later.


    Charles Babbage and Vigenére

    As mentioned earlier, the strength of the Vigenére crypto is that a letter can be crypted on a number of
    different ways. If the keyword is KING is used, there's four different ways to crypt a given letter.
    The same apply to words that's crypted. The word "the" can be crypted as, DQR, BUK, GNO or ZRM depending on
    the words relation to the keyword KING. You get no clues from the frequency analysis.
    This making the decrypting much harder, but not impossible.
    A man named Charles Babbage, born 1791, was the first one to break this kind of crypto.
    Among many things, he was devoted to statistics. He was one of the first one making statistic on born/death relations,
    today commonly used by insurance companies.

    He thought that if there's only four ways to crypt the word "the", and the word is used many times in the text,
    the possibility that the same crypto variant is repeated on a number of places in the text is rather significant.
    The longer the text, the greater the chance. It was this kind of repetition that lead Babbage to the decryption
    of the Vigenére crypto.

    Babbage stated some fairly simple steps to break the Vigenére crypto.
    Look for letter sequences that repeat more that once in the text. There's a possibility that it's the same word
    crypted with the same part of the keyword. The distance between the repetitions and the distance from the beginning
    of the text, gives you some clues of the length of the keyword. When you know the length of the keyword, you know
    how many crypto alphabet that was used to crypt the text. If you use just one alphabet, it's just a
    monoalphabetic crypto, and that you know how to decrypt.

    If you found out that the keyword is five letters, you use the first alphabet for letter 1, 6 ,11 and so on.
    For letter 2, 7, 12... you use the second alphabet and so on. You only have to use as many alphabet as there
    are letters in the keyword. But how do we know what alphabet to use?
    You already know the answer: Frequency analysis.
    When you know the length of the keyword, you just have to use frequency analysis.
    Remember that the crypto alphabet is just a clear alphabet rotated one step in relation to the previous one.

    Implementing Vigenére in ASM
    ============================
    To implement Vigenére crypto in asm we need a lot of Vigenére tables in memory. To this we need a lot of
    index and key char pointers. NOT
    This was my first approach, but if we stop and think a bit we can reduce it to this.

    Crypting: add al,ah ;al is clear char and ah is key char sub al,"A"+"A" cmp al,25 jng @F sub al,26 ;Overflow, wrap around@@: add al,"A" ;al is now crypted char
    Decrypting:
    sub al,ah ;al is crypt char and ah is key char
    cmp al,0
    jge @F
    add al,26 ;Underflow, wrap around.
    @@:
    add al,"A" ;al is now clear char

    To understand the code above, remember that the Vigenére table is just 26 alphabets where each one is
    rotated one step in relation to the previous. If we simplify it a bit and just use one alphabet,
    a-z, we can look at it with a new approach. In the above example with the word "the" and the key
    "KING" we get "t" as the first letter to crypt with key char "K". As you remember,
    we go to the "t" column in the clear alphabet, and from there down to the line starting with k.
    In the point of intersection we find "D".

    Another way to look at it is, go to the "K" column of the alphabet starting with "A", column 10 (or "A" - "K",
    where the "A"-column is column 0). Add the number of the "T" column, column 19, to the "K" column and we get 29.
    As the English alphabet only have 26 letters we get an overflow, or wrap around of 4 (remember "A" column is 0).
    If we add 4 to 0 we end up in the "D" column, which is the substitution letter for "T" with the key char "K".

    We apply the same rules for the decryption, but here we subtract the key character from the crypted character.
    Instead of overflow we look for underflow and if this happen, we shift it up 26 letters.

    @Detten add link vigenere.asm
    The complete source code can be found here, if Detten is so kind and add a link to it ;-).

    And last, an exercise in Vigenére:
    BBLM RS VRJ XTYOETOSWP UNTYOJH XBLHCOQ DLVTSQX FHO T PRQMJLJ UJG?
    QXJ CD FJDG YK JWTBTKM FHO BB DCXLYCHDS HYW WSBUDTOS NZ IUAA GNNS,
    MQE QDMYC BB UUOI NZ VJRTI LLZVNRKOX.

    QSTC IU DMY OBOFGBJHNX KEVGJYY XAOVSH UYW TIPUD?
    YCHCIE SX ODBWG C PJUEANR....MSSEJ BB UUSSA EAN WJYQY NARCMOS.

    Avoiding Vigenére
    =================
    The strength of the Vigenére crypto also makes this kind of crypto harder to use.
    One candidate to a crypto stronger than the monoalphabetic crypto, but easier to use than the
    Vigenére crypto is the homophonic substitution crypto.

    In this crypto you substitute a letter with many letters, and the number of substitute characters is
    proportional to the frequency of the letter. If for example the letter a have a frequency of 9%,
    we assign 8 characters to substitute for a. For every occurence of the letter a in the clear text,
    we substitute it with any of the 8 characters we assigned to a, not important which one.
    After crypting the text, every character substituted for a then have about 1% frequency in the crypted text.
    If b, or any letter, have 1% frequency, we only have to substitute it with 2 characters.
    When all letters in the clear text is crypted, every character then have about 1% frequency in the crypted text.

    An example of homophonic substitution crypto. Here number is used.a b c d e f g h i j k l m n o p q r s t u v w x y z09 48 13 01 14 10 06 23 32 15 04 26 22 18 00 38 94 29 11 17 08 34 60 28 21 0212 81 41 03 16 31 25 39 70 37 27 58 05 95 35 19 20 61 89 5233 62 45 24 50 73 51 59 07 40 36 30 63 47 79 44 56 83 84 66 54 42 76 4353 46 65 88 71 72 77 86 4967 55 68 93 91 90 80 96 6978 57 99 7592 64 85 74 97 82 87 98


    With a frequency of 1% for every character, there's no way to use
    frequency analysis on the crypted text. Is this unbreakable? NOT
    There's a number of discrete clues for a clever decrypter.
    Every letter in any language have its own quality and relation to other letters.
    This can be distinguished even if homophonic substitution crypto is used.

    In english the letter q is always followed by the letter u. No other letter can follow q.
    If we want to decrypt an english text crypted with homophonic substitution we now that q is a rare
    letter probably only substituted with one character (or number).
    We also know that the letter u have e frequency of about 3% of all letters in an english text and therefore
    probably substituted with 3 characters.

    If we find a character in the crypted text that is always followed by the same three characters,
    we have reason to believe that these characters stands for the letter u, and the first stand for q.
    Other letter are harder to pick, but their internal relation reveals which one it is.
    It's possible to break this kind of crypto, but it's a lot safer than a simple monoalphabetic crypto.

    At first glance, the homophobic substitution crypto seems to be some kind of polyalphabetic crypto.
    Every clear text letter can be substituted with a number of characters, but there's a significant difference.
    In the example above, the letter a is represented by 8 different numbers.
    These numbers represent the letter a and only the letter a. In a polyalphabetic crypto a clear text letter
    can be substituted with different letters, but here the substitution letters can represent different clear
    text letters. Because of this, the homophonic substitution crypto is said to be a monoalphabetic crypto.
    By the time the crypto alphabet is made, it's used through out the whole crypto.
    It makes no difference that there's a number of substitute for a letter.
    If you use a polyalphabetic crypto, you constantly change between different crypto alphabets.


    My way of implementing homophonic substitution crypto in asm can be found here.

    And now a homophonic exercise:


    HNE 0IQWtG OY98CKÂ5u YfTBÅ7| pA vÏÃ2ä] éJ 1W[UZÂjweh3 XÈ i
    åÅçgÄvâ ìqmV-sSkboDÁÏI6 }dcaäYz xÉÆÊÇÎË ÍL åét2Wë ãSáÌèDíæT
    2.2, 9u ï]HÂ0|Cà X13-5Ã ëZ7gycK. Ulî Ëpx8MEçeikÅÄI ÏtDQw1GB o
    äJÁ æA 3éVAObfuch[ jqÇvsz| åWÃ2Â] ÈÆmV-ÎSád}xíïÉ 2.2 Êçg
    vÅI2Ïë âãàA-îSHÌèDK0T ]EZì5t9Q GËäUé7u, årWc{ ÂB Å|xy1O3 vÏeÀ
    kNäJ Dpën ÄV åéÃ2W].






    Playfair

    The playfair crypto was created by Lyon Playfair. This crypto substitutes every two letters in the clear
    text with another letter pair. To crypt and decrypt a text, the sender and receiver must first agree on a keyword to use.
    The crypto is used like this.
    Write out the letters in an 5 x 5 square (a-z) and let I and J share the same place. Start with the keyword .
    If we use the keyword CHARLES we get:


    C H A R LE S B D FG I/J K M NO P Q T UV W X Y Z


    Then you divide the message into letter pairs, called bigram. Every bigram must consist of two different letters.
    Therefore you put in an x for double letters that otherwise would end up in the same bigram.
    Also put an x at the end if the text end with a single letter.

    Clear text:
    We meet at hammersmith bridge at seven.

    Text in bigram:
    we-me-et-at-ha-mx-me-rs-mi-th-br-id-ge-at-se-ve-nx

    Then the crypting start.
    Every bigram fall into one of the following categories.
    1 Both letters is on the same line
    2 Both letter is in the same column
    3 Neither 1 or 2.

    1 If both letter is in the same row, substitute them with the letter to the right if each one.
    MI becomes NK. If the one letter is the last in the row, substitute it with the first letter in the row.

    2 If both letters is in the same column, substitute them with the letter in the column below each one. GE becomes OG. If one letter is in the last row, substitute it with the letter from the first row. YR becomes RD.

    3 If neither 1 or 2 apply, we do like this. To crypt the first letter, follow the row it's on until you
    reach the column where the second letter is. The letter where the two intersect is used as a substitute for
    letter one. When you crypt the second letter, follow the row it's on until you reach the column of the first
    letter. The letter where the two intersect is used as a substitute for letter 2. VI becomes WG and SV becomes EW.
    If you look at the clear text letters as the corner of a diagonal, the substitute letters is in the opposite corners.

    The bigram text:
    we me et at ha mx me rs mi th br id ge at se ve nx

    The crypted text:
    VSDGODQRARKYDGDHNKRPADSMOGQRBSCGKZ






    ADFGVX crypto

    In ADFGVX crypto, both substitution and transposition is used. The crypto is used like this.
    In a 6 x 6 square, 36 positions, write out the letters a-z and the numbers 0-9 in a random order.
    Both rows and columns in the square is named with the letters A, D, F, G, V and X.
    The order of the letters in the square becomes a part of the key and therefore the receiver must have a
    copy of the square.

    A D F G V XA 8 p 3 d 1 nD l t 4 o a hF 7 k b c 5 zG j u 6 w g mV x s v i r 2X 9 e y 0 f q


    The first step is to look at in which row and column each letter in the text is.
    Write down the two letters that refer to this position in the square.
    In this example 8 is substituted with AA and p with AD.

    Message:
    Attack at 2230

    Crypt step 1:A t t a c k a t 2 2 3 0DV DD DD DV FG FD DV DD VX VX AF XG


    So far it is a simple monoalphabetic substitution crypto, breakable with frequency analysis.
    The second step in the crypto is the traspose. The traspose is based on a keyword, and in this example we use MARK.
    This keyword must also be know by the receiver.

    The transposition is done like this:
    Write out the letters of the keyword as the first row of a new square.
    Then write out the text from the first step of the crypto below the keyword using the same row length as the keyword.

    Then arrange the columns so that the letters in the keyword is sorted from a to z.
    The other columns follows the keyword columns.

    M A R K -> A K M RD V D D V D D DD D D V D V D DF G F D G D F FD V D D V D D DA V X G V G A XA D G X D X A G

    Final crypto text:VDDDDVDDGDFFVDDDVGAXDXAG
    The reason for using A, D, F, G, V and X is that they are the letters in the Morse alphabet that
    differs the most from each other. This was done to reduce the number of errors when the text was sent.

  2. #152
    پروفشنال Morteza_SOS's Avatar
    تاريخ عضويت
    Apr 2006
    پست ها
    577

    پيش فرض

    Level : beginner

    This is a small, and by no means complete, digestion of some crypto techniques.
    Featuring :
    - Transposition
    - Substitution
    - Frequency analysis
    - Le Chiffre Indéchiffrable
    - Charles Babbage and Vigenére
    - Playfair
    - ADFGVX crypto




    Transposition

    One method of crypting a text is transposition.
    One simple traspose is to write out the message on two rows.
    Letters 1,3, 5 and so on, you write on the first row.
    Letters 2, 4, 6 etc. you write on the second row.
    The message:
    Your secret is your prisoner, let it go and you become its prisoner.

    Row 1:
    Yusceiyupioelyyonyueoeypioi

    Row 2:
    orertsorrsnreigadobcmisrsnr

    Crypted text:
    Yusceiyupioelyyonyueoeypioiorertsorrsnreigadobcmis rsnr


    Substitution

    Another method is substitution where you substitute one letter with another letter.
    Code
    ====
    A code substitute a word or group of letter.

    Monoalphabetic substitution
    =======================
    One variant is the Caesar roll. This is based on crypto alphabet that's shifted a number
    of steps relative the clear text alphabet. It's common in cryptography to write out the
    clear text in lowercase letter and the crypted text in uppercase letter.

    Clear alphabet:
    abcdefghijklmnopqrstuvwxyz

    Crypto alphabet:
    DEFGHIJKLMNOPQRSTUVWXYZABC (here with a three letter right rotation)

    Clear text:
    veni, vidi vici

    Crypto text:
    YHQL, YLGL, YLFL

    To crypt a text, you write out the crypto alphabet under the clear alphabet.
    Then you take the letter from the text, here starting with "v", and go to the
    column where v is in the clear alphabet.
    Look in the same column in the crypto alphabet to get the letter to substitute with.
    Here v is substituted with Y. Repeat this for all letters in the text.

    As you may see, this is not a very strong protection. With a computer it's easy to
    try all possible shifts, where each shift can be regarded as a key to the crypto.

    Monoalphabetic substitution with key
    ====================================
    If you choose a more general algorithm where the clear alphabet can be reordered in any possible way,
    you get 400 000 000 000 000 000 000 000 000 possible keys to choose from. If the enemy gets hold of
    the crypted text and he knows the algorithm, he still have to test all keys to decrypt the message.
    If he test one key per second, he approximately would need the time equal the age of
    universe multiplied with 10e9.

    Clear alphabet:
    abcdefghijklmnopqrstuvwxyz

    Crypto alphabet:
    DJKTUVCWNOLPAEGFHIQRXYMSZB ("random" order)

    Clear text:
    ettu, brute?

    Crypto text:
    URRX, JIXRU?

    It can be shown with mathematical proof, that if you use a random key as long as the text you want to crypt,
    the crypted text CAN NOT be decrypted if you don't know the key. In any crypto a weak spot is repetitions
    that occur if you use a to short key. Another thing to remember is that you can't use the same key twice,
    and you must use a really random key. If you use the key more then once, there's methods to break the crypto.

    A variant to this, but with a less number of keys, is to use a key or key phrase. Instead of a random alphabet
    you take a key or a key phrase, for example "Julius Ceasar". Remove all spaces and duplicate letters and use
    the rest, JULISCAER, as beginning of the crypto alphabet. The rest of the alphabet is just a shift beginning
    where the keyword ends and with the letters in the keyword removed from the alphabet.

    Clear alphabet:
    abcdefghijklmnopqrstuvwxyz

    Crypto alphabet:
    JULISCAERTVWXYZBDFGHKMNOPQ

    This can also be rotated a number of steps to.
    Crypto alphabet:
    CAERTVWXYZBDFGHKMNOPQJULIS

    A good thing about this is that it is easy to remember the key word or key phrase. The simplicity in combination
    with the strength made this the common method to crypt a text the first thousand years a.c.

    Anyone interested in cracking a monoalphabetic text can look at the mono crackme in the crackme's.


    But there is ways to break this crypto, the Arabs was the first ones out.


    Frequency analysis

    The oldest known description, by an Arab, to break a monoalphabetic crypto is from 800 a.c.
    The trick is that in any given language there's letters that's used more frequently.
    If you know the letter frequency for a language, you take the letters frequency in the crypted
    text and substitute it with the one that have about the same frequency for that language.
    It's relatively easy to make a qualified guess what letter it is.
    The same rules can be applied on one, two, three or more, letter words.

    As you are a cracker, it's easy to write a small app to analyse some text files on your computer.
    What kind of text you analyse of course affects the result of the letter frequency. If you for example
    analyze a sorce code file, you get a funny letter and word distribution. If it's a *.asm file you get a
    lot of three letter words like: eax,ebx,ecx...:-).


    Le Chiffre Indéchiffrable

    For many centuries the monoalphabetic substitution crypto was the prevailing method to write a secret text.
    But after the Arabs invention of the frequency analyze, this method was no longer a safe one to use.
    The original idea for this new crypto came from a man named Leon Battista Alberti, born 1404.
    His idea was use two or more crypto alphabet and switch between them.

    Clear alphabet:
    abcdefghijklmnopqrstuvwxyz

    Crypto alphabet 1:
    FZBVKIXAYMEPLSDHJORGNQCUTW

    Crypto alphabet 2:
    GOXBFWTHQILAZPJDESYVCRKUHN

    If we crypt the word "hello" we use the first alphabet for h, that become A.
    For the second letter e we use the second alphabet, e becomes F, and so on.
    With this method hello becomes AFPAD.

    A man named Blaise de Vigenére, born 1523, developed this idea further.
    Instead of using two or three alphabet, he used 26 (for a-z for English).
    Although he based his work on ideas of previous thinkers, this method is known as the Vigenére crypto.
    The use of more than one crypto alphabet gives this type of crypto the name polyalphabetic crypto.

    The first step to use this is to write out a Vigenére table. This is done by writing down a clear alphabet
    followed by 26 crypto alphabets, each one rotated on step in relation to the previous one.

    abcdefghijklmnopqrstuvwxyz1 BCDEFGHIJKLMNOPQRSTUVWXYZA2 CDEFGHIJKLMNOPQRSTUVWXYZAB3 DEFGHIJKLMNOPQRSTUVWXYZABC4 EFGHIJKLMNOPQRSTUVWXYZABCD5 FGHIJKLMNOPQRSTUVWXYZABCDE6 GHIJKLMNOPQRSTUVWXYZABCDEF7 HIJKLMNOPQRSTUVWXYZABCDEFG8 IJKLMNOPQRSTUVWXYZABCDEFGH9 JKLMNOPQRSTUVWXYZABCDEFGHI10 KLMNOPQRSTUVWXYZABCDEFGHIJ11 LMNOPQRSTUVWXYZABCDEFGHIJK12 MNOPQRSTUVWXYZABCDEFGHIJKL13 NOPQRSTUVWXYZABCDEFGHIJKLM14 OPQRSTUVWXYZABCDEFGHIJKLMN15 PQRSTUVWXYZABCDEFGHIJKLMNO16 QRSTUVWXYZABCDEFGHIJKLMNOP17 RSTUVWXYZABCDEFGHIJKLMNOPQ18 STUVWXYZABCDEFGHIJKLMNOPQR19 TUVWXYZABCDEFGHIJKLMNOPQRS20 UVWXYZABCDEFGHIJKLMNOPQRST21 VWXYZABCDEFGHIJKLMNOPQRSTU22 WXYZABCDEFGHIJKLMNOPQRSTUV23 XYZABCDEFGHIJKLMNOPQRSTUVW24 YZABCDEFGHIJKLMNOPQRSTUVWX25 ZABCDEFGHIJKLMNOPQRSTUVWXY26 ABCDEFGHIJKLMNOPQRSTUVWXYZ



    The first row is a crypto alphabet with a Caesar roll, a rotation of one step.
    The second one have a two step rotation and so on.
    To use it, you use a new row for each letter you crypt.
    To decrypt it the user must know which row to use for which letter.
    You maybe use row 5 for the first letter, row 14 for the second, row 21 for the third and so on.

    To decrypt the text the receiver must know which row shifts to use.
    One way to do this is to use a key word.
    To crypt the message "Begin attack at sundown" and the key GREEN we do like this.

    Write out the key word above the message over and over, so each letter in the message
    is linked to a letter in the key word.


    GREENGREENGREENGREENbeginattackatsundown

    Then you create the crypto text like this:
    Crypt the letter b by taking the letter in the key word above, here it is G.
    This letter is the index to a row in the Vigenére table.
    The row beginning with G, row 6, is the crypto alphabet to use for
    the first letter b. In the row for the clear alphabet, go to the column
    for the letter b. To find the substitution letter, follow this column down
    to row 6, here you find the letter H to substitute for b.
    Repeat this procedure for the letter e. The key letter above e is R which gives
    us the row that start with R, row number 17. In the clear alphabet, go to the column
    for the letter e in the clear alphabet, follow this column down to row 17 to get the substitution letter V.

    Repeat this for each letter in the message.

    Each letter in the keyword gives us a different crypto alphabet to use.
    The number of letters in the key word gives us the number of rows to use in the
    Vigenére table. In this example we use four rows, G, R, E and N (E is doubled here).

    The message "beginattackatsundown" crypted with the keyword GREEN comes out as:
    HVKMAGKXEPQRXWHTUSAA

    With a longer keyword, or a key sentence, you add more rows from the table you make the crypto more
    difficult to break. The frequency analysis, described above, has no effect on this kind of crypto.
    If you have a word with at double letter, like attack above, the first t becomes K and the second becomes X.
    If you do a frequency analysis of this, there's no way to tell that this is the letter t.
    Another strength is the enormous number of keys you can use. Any word in the book can be used,
    you even can make up you own words. It's just not possible to try all possible combinations.
    The work by Vigenéres was published in Tracicté des Chiffres 1586 but did not come to common use
    until 200 years later.


    Charles Babbage and Vigenére

    As mentioned earlier, the strength of the Vigenére crypto is that a letter can be crypted on a number of
    different ways. If the keyword is KING is used, there's four different ways to crypt a given letter.
    The same apply to words that's crypted. The word "the" can be crypted as, DQR, BUK, GNO or ZRM depending on
    the words relation to the keyword KING. You get no clues from the frequency analysis.
    This making the decrypting much harder, but not impossible.
    A man named Charles Babbage, born 1791, was the first one to break this kind of crypto.
    Among many things, he was devoted to statistics. He was one of the first one making statistic on born/death relations,
    today commonly used by insurance companies.

    He thought that if there's only four ways to crypt the word "the", and the word is used many times in the text,
    the possibility that the same crypto variant is repeated on a number of places in the text is rather significant.
    The longer the text, the greater the chance. It was this kind of repetition that lead Babbage to the decryption
    of the Vigenére crypto.

    Babbage stated some fairly simple steps to break the Vigenére crypto.
    Look for letter sequences that repeat more that once in the text. There's a possibility that it's the same word
    crypted with the same part of the keyword. The distance between the repetitions and the distance from the beginning
    of the text, gives you some clues of the length of the keyword. When you know the length of the keyword, you know
    how many crypto alphabet that was used to crypt the text. If you use just one alphabet, it's just a
    monoalphabetic crypto, and that you know how to decrypt.

    If you found out that the keyword is five letters, you use the first alphabet for letter 1, 6 ,11 and so on.
    For letter 2, 7, 12... you use the second alphabet and so on. You only have to use as many alphabet as there
    are letters in the keyword. But how do we know what alphabet to use?
    You already know the answer: Frequency analysis.
    When you know the length of the keyword, you just have to use frequency analysis.
    Remember that the crypto alphabet is just a clear alphabet rotated one step in relation to the previous one.

    Implementing Vigenére in ASM
    ============================
    To implement Vigenére crypto in asm we need a lot of Vigenére tables in memory. To this we need a lot of
    index and key char pointers. NOT
    This was my first approach, but if we stop and think a bit we can reduce it to this.

    Crypting: add al,ah ;al is clear char and ah is key char sub al,"A"+"A" cmp al,25 jng @F sub al,26 ;Overflow, wrap around@@: add al,"A" ;al is now crypted char
    Decrypting:
    sub al,ah ;al is crypt char and ah is key char
    cmp al,0
    jge @F
    add al,26 ;Underflow, wrap around.
    @@:
    add al,"A" ;al is now clear char

    To understand the code above, remember that the Vigenére table is just 26 alphabets where each one is
    rotated one step in relation to the previous. If we simplify it a bit and just use one alphabet,
    a-z, we can look at it with a new approach. In the above example with the word "the" and the key
    "KING" we get "t" as the first letter to crypt with key char "K". As you remember,
    we go to the "t" column in the clear alphabet, and from there down to the line starting with k.
    In the point of intersection we find "D".

    Another way to look at it is, go to the "K" column of the alphabet starting with "A", column 10 (or "A" - "K",
    where the "A"-column is column 0). Add the number of the "T" column, column 19, to the "K" column and we get 29.
    As the English alphabet only have 26 letters we get an overflow, or wrap around of 4 (remember "A" column is 0).
    If we add 4 to 0 we end up in the "D" column, which is the substitution letter for "T" with the key char "K".

    We apply the same rules for the decryption, but here we subtract the key character from the crypted character.
    Instead of overflow we look for underflow and if this happen, we shift it up 26 letters.

    @Detten add link vigenere.asm
    The complete source code can be found here, if Detten is so kind and add a link to it ;-).

    And last, an exercise in Vigenére:
    BBLM RS VRJ XTYOETOSWP UNTYOJH XBLHCOQ DLVTSQX FHO T PRQMJLJ UJG?
    QXJ CD FJDG YK JWTBTKM FHO BB DCXLYCHDS HYW WSBUDTOS NZ IUAA GNNS,
    MQE QDMYC BB UUOI NZ VJRTI LLZVNRKOX.

    QSTC IU DMY OBOFGBJHNX KEVGJYY XAOVSH UYW TIPUD?
    YCHCIE SX ODBWG C PJUEANR....MSSEJ BB UUSSA EAN WJYQY NARCMOS.

    Avoiding Vigenére
    =================
    The strength of the Vigenére crypto also makes this kind of crypto harder to use.
    One candidate to a crypto stronger than the monoalphabetic crypto, but easier to use than the
    Vigenére crypto is the homophonic substitution crypto.

    In this crypto you substitute a letter with many letters, and the number of substitute characters is
    proportional to the frequency of the letter. If for example the letter a have a frequency of 9%,
    we assign 8 characters to substitute for a. For every occurence of the letter a in the clear text,
    we substitute it with any of the 8 characters we assigned to a, not important which one.
    After crypting the text, every character substituted for a then have about 1% frequency in the crypted text.
    If b, or any letter, have 1% frequency, we only have to substitute it with 2 characters.
    When all letters in the clear text is crypted, every character then have about 1% frequency in the crypted text.

    An example of homophonic substitution crypto. Here number is used.a b c d e f g h i j k l m n o p q r s t u v w x y z09 48 13 01 14 10 06 23 32 15 04 26 22 18 00 38 94 29 11 17 08 34 60 28 21 0212 81 41 03 16 31 25 39 70 37 27 58 05 95 35 19 20 61 89 5233 62 45 24 50 73 51 59 07 40 36 30 63 47 79 44 56 83 84 66 54 42 76 4353 46 65 88 71 72 77 86 4967 55 68 93 91 90 80 96 6978 57 99 7592 64 85 74 97 82 87 98


    With a frequency of 1% for every character, there's no way to use
    frequency analysis on the crypted text. Is this unbreakable? NOT
    There's a number of discrete clues for a clever decrypter.
    Every letter in any language have its own quality and relation to other letters.
    This can be distinguished even if homophonic substitution crypto is used.

    In english the letter q is always followed by the letter u. No other letter can follow q.
    If we want to decrypt an english text crypted with homophonic substitution we now that q is a rare
    letter probably only substituted with one character (or number).
    We also know that the letter u have e frequency of about 3% of all letters in an english text and therefore
    probably substituted with 3 characters.

    If we find a character in the crypted text that is always followed by the same three characters,
    we have reason to believe that these characters stands for the letter u, and the first stand for q.
    Other letter are harder to pick, but their internal relation reveals which one it is.
    It's possible to break this kind of crypto, but it's a lot safer than a simple monoalphabetic crypto.

    At first glance, the homophobic substitution crypto seems to be some kind of polyalphabetic crypto.
    Every clear text letter can be substituted with a number of characters, but there's a significant difference.
    In the example above, the letter a is represented by 8 different numbers.
    These numbers represent the letter a and only the letter a. In a polyalphabetic crypto a clear text letter
    can be substituted with different letters, but here the substitution letters can represent different clear
    text letters. Because of this, the homophonic substitution crypto is said to be a monoalphabetic crypto.
    By the time the crypto alphabet is made, it's used through out the whole crypto.
    It makes no difference that there's a number of substitute for a letter.
    If you use a polyalphabetic crypto, you constantly change between different crypto alphabets.


    My way of implementing homophonic substitution crypto in asm can be found here.

    And now a homophonic exercise:


    HNE 0IQWtG OY98CKÂ5u YfTBÅ7| pA vÏÃ2ä] éJ 1W[UZÂjweh3 XÈ i
    åÅçgÄvâ ìqmV-sSkboDÁÏI6 }dcaäYz xÉÆÊÇÎË ÍL åét2Wë ãSáÌèDíæT
    2.2, 9u ï]HÂ0|Cà X13-5Ã ëZ7gycK. Ulî Ëpx8MEçeikÅÄI ÏtDQw1GB o
    äJÁ æA 3éVAObfuch[ jqÇvsz| åWÃ2Â] ÈÆmV-ÎSád}xíïÉ 2.2 Êçg
    vÅI2Ïë âãàA-îSHÌèDK0T ]EZì5t9Q GËäUé7u, årWc{ ÂB Å|xy1O3 vÏeÀ
    kNäJ Dpën ÄV åéÃ2W].






    Playfair

    The playfair crypto was created by Lyon Playfair. This crypto substitutes every two letters in the clear
    text with another letter pair. To crypt and decrypt a text, the sender and receiver must first agree on a keyword to use.
    The crypto is used like this.
    Write out the letters in an 5 x 5 square (a-z) and let I and J share the same place. Start with the keyword .
    If we use the keyword CHARLES we get:


    C H A R LE S B D FG I/J K M NO P Q T UV W X Y Z


    Then you divide the message into letter pairs, called bigram. Every bigram must consist of two different letters.
    Therefore you put in an x for double letters that otherwise would end up in the same bigram.
    Also put an x at the end if the text end with a single letter.

    Clear text:
    We meet at hammersmith bridge at seven.

    Text in bigram:
    we-me-et-at-ha-mx-me-rs-mi-th-br-id-ge-at-se-ve-nx

    Then the crypting start.
    Every bigram fall into one of the following categories.
    1 Both letters is on the same line
    2 Both letter is in the same column
    3 Neither 1 or 2.

    1 If both letter is in the same row, substitute them with the letter to the right if each one.
    MI becomes NK. If the one letter is the last in the row, substitute it with the first letter in the row.

    2 If both letters is in the same column, substitute them with the letter in the column below each one. GE becomes OG. If one letter is in the last row, substitute it with the letter from the first row. YR becomes RD.

    3 If neither 1 or 2 apply, we do like this. To crypt the first letter, follow the row it's on until you
    reach the column where the second letter is. The letter where the two intersect is used as a substitute for
    letter one. When you crypt the second letter, follow the row it's on until you reach the column of the first
    letter. The letter where the two intersect is used as a substitute for letter 2. VI becomes WG and SV becomes EW.
    If you look at the clear text letters as the corner of a diagonal, the substitute letters is in the opposite corners.

    The bigram text:
    we me et at ha mx me rs mi th br id ge at se ve nx

    The crypted text:
    VSDGODQRARKYDGDHNKRPADSMOGQRBSCGKZ






    ADFGVX crypto

    In ADFGVX crypto, both substitution and transposition is used. The crypto is used like this.
    In a 6 x 6 square, 36 positions, write out the letters a-z and the numbers 0-9 in a random order.
    Both rows and columns in the square is named with the letters A, D, F, G, V and X.
    The order of the letters in the square becomes a part of the key and therefore the receiver must have a
    copy of the square.

    A D F G V XA 8 p 3 d 1 nD l t 4 o a hF 7 k b c 5 zG j u 6 w g mV x s v i r 2X 9 e y 0 f q


    The first step is to look at in which row and column each letter in the text is.
    Write down the two letters that refer to this position in the square.
    In this example 8 is substituted with AA and p with AD.

    Message:
    Attack at 2230

    Crypt step 1:A t t a c k a t 2 2 3 0DV DD DD DV FG FD DV DD VX VX AF XG


    So far it is a simple monoalphabetic substitution crypto, breakable with frequency analysis.
    The second step in the crypto is the traspose. The traspose is based on a keyword, and in this example we use MARK.
    This keyword must also be know by the receiver.

    The transposition is done like this:
    Write out the letters of the keyword as the first row of a new square.
    Then write out the text from the first step of the crypto below the keyword using the same row length as the keyword.

    Then arrange the columns so that the letters in the keyword is sorted from a to z.
    The other columns follows the keyword columns.

    M A R K -> A K M RD V D D V D D DD D D V D V D DF G F D G D F FD V D D V D D DA V X G V G A XA D G X D X A G

    Final crypto text:VDDDDVDDGDFFVDDDVGAXDXAG
    The reason for using A, D, F, G, V and X is that they are the letters in the Morse alphabet that
    differs the most from each other. This was done to reduce the number of errors when the text was sent.

  3. #153
    پروفشنال Morteza_SOS's Avatar
    تاريخ عضويت
    Apr 2006
    پست ها
    577

    پيش فرض

    Level : newbie

    Bypassing EXE Protector v2.01a.
    The program is supposed to protect the exe file with a password.

    I was looking in the other forum and I saw someone asking about this protection:
    They were asking about EXEProtector v1.37a
    I did a search on the net for it but I came up with this one.
    So lets get started:
    I put my crackme <int21h.exe> in this protection.
    The program is supposed to protect the exe file with a password.
    Lets run the program before we do anything.
    We run it and find that it has a window title <Password Check> then in the window it has in the box <Enter the password :> It then has a <Cancel> and a <OK> button.
    Lets run this through w32dsm89 and look at some strings:
    When I look at the strings I see these 2 that catch my interest:
    “You have not supplied a password” and “You have supplied a wrong password”
    Let’s take a look at the code:
    * Reference To: MSVBVM60.__vbaStrCmp, Ord:0000h
    :00403A9A E869D9FFFF Call 00401408
    :00403A9F 85C0 test eax, eax
    :00403AA1 0F85AF000000 jne 00403B56
    :00403AA7 B904000280 mov ecx, 80020004
    :00403AAC 894D98 mov dword ptr [ebp-68], ecx
    :00403AAF 6A0A push 0000000A
    :00403AB1 58 pop eax
    :00403AB2 894590 mov dword ptr [ebp-70], eax
    :00403AB5 894DA8 mov dword ptr [ebp-58], ecx
    :00403AB8 8945A0 mov dword ptr [ebp-60], eax

    * Possible StringData Ref from Code Obj ->"PPassword"
    |
    :00403ABB C78578FFFFFFD0224000 mov dword ptr [ebp+FFFFFF78], 004022D0
    :00403AC5 89B570FFFFFF mov dword ptr [ebp+FFFFFF70], esi
    :00403ACB 8D9570FFFFFF lea edx, dword ptr [ebp+FFFFFF70]
    :00403AD1 8D4DB0 lea ecx, dword ptr [ebp-50]

    * Reference To: MSVBVM60.__vbaVarDup, Ord:0000h
    |
    :00403AD4 E83FD8FFFF Call 00401318

    * Possible StringData Ref from Code Obj ->"YYou have not supplied a password."
    |
    :00403AD9 C7458888224000 mov [ebp-78], 00402288
    :00403AE0 897580 mov dword ptr [ebp-80], esi
    :00403AE3 8D5580 lea edx, dword ptr [ebp-80]
    :00403AE6 8D4DC0 lea ecx, dword ptr [ebp-40]

    This is the nag you get if you do not enter anything for the password:
    The one I am really interested in is this one.

    * Referenced by a (U)nconditional or (C)onditional Jump at Address:
    |:00403B7F(C)
    |
    :00403C0A B904000280 mov ecx, 80020004
    :00403C0F 894D98 mov dword ptr [ebp-68], ecx
    :00403C12 6A0A push 0000000A
    :00403C14 58 pop eax
    :00403C15 894590 mov dword ptr [ebp-70], eax
    :00403C18 894DA8 mov dword ptr [ebp-58], ecx
    :00403C1B 8945A0 mov dword ptr [ebp-60], eax

    * Possible StringData Ref from Code Obj ->"PPassword"
    |
    :00403C1E C78578FFFFFFD0224000 mov dword ptr [ebp+FFFFFF78], 004022D0
    :00403C28 89B570FFFFFF mov dword ptr [ebp+FFFFFF70], esi
    :00403C2E 8D9570FFFFFF lea edx, dword ptr [ebp+FFFFFF70]
    :00403C34 8D4DB0 lea ecx, dword ptr [ebp-50]

    * Reference To: MSVBVM60.__vbaVarDup, Ord:0000h
    |
    :00403C37 E8DCD6FFFF Call 00401318

    * Possible StringData Ref from Code Obj ->"YYou have supplied a worng password."
    |
    :00403C3C C74588E8224000 mov [ebp-78], 004022E8
    :00403C43 897580 mov dword ptr [ebp-80], esi
    :00403C46 8D5580 lea edx, dword ptr [ebp-80]
    :00403C49 8D4DC0 lea ecx, dword ptr [ebp-40]

    This is the nag you get when you enter a wrong password.
    So lets see where is comes from:
    I see this a little ways up in the code:

    * Referenced by a (U)nconditional or (C)onditional Jump at Address:
    |:00403B7F(C)

    Let’s go check that out…

    * Reference To: MSVBVM60.__vbaStrCmp, Ord:0000h
    |
    :00403B78 E88BD8FFFF Call 00401408
    :00403B7D 85C0 test eax, eax
    :00403B7F 0F8585000000 jne 00403C0A
    :00403B85 390568534000 cmp dword ptr [00405368], eax
    :00403B8B 750F jne 00403B9C
    :00403B8D 6868534000 push 00405368
    :00403B92 681C224000 push 0040221C

    Well now I think we can start Olly up and set us a breakpoint on:
    :00403B78 E88BD8FFFF Call 00401408

    This call is a string compare for VB600 so you can expect for a string to be compared to another one.
    Open up the int21h.exe in Olly and set a breakpoint @ address 00403B78.
    Run the program <F9>. When the messagebox comes up asking for the password enter this; 12345678 then hit the <Ok> button.
    Olly breaks and we see this in the stack window:
    0012F404 0014C954 UNICODE "int21h"
    0012F408 0014C6D4 UNICODE "12345678"
    I would guess that the password would be <int21h>.
    Anyway hit <F8> and go through the call.
    You should now be here:
    :00403B7D 85C0 test eax, eax
    Right click the register EAX and then select <Zero>.
    Keep hitting <F8> till you are here:
    :00403BFE E821D7FFFF Call 00401324
    Now hit <F7>
    Hit <F7> again.
    You should now be here:
    6AAA7C33 > 55 PUSH EBP
    Now hit <F8> till you reach this:
    6AAA7D64 FF15 0C119D6A CALL DWORD PTR DS:[<&KERNEL32.CreateProc>; kernel32.CreateProcessW
    I wonder what the stack looks like:
    Take a look:
    0012F374 00000000 |ModuleFileName = NULL
    0012F378 0014CC14 |CommandLine = "C:targetz__70043.exe"
    0012F37C 00000000 |pProcessSecurity = NULL
    0012F380 00000000 |pThreadSecurity = NULL
    0012F384 00000000 |InheritHandles = FALSE
    0012F388 00000000 |CreationFlags = 0
    0012F38C 00000000 |pEnvironment = NULL
    0012F390 00000000 |CurrentDir = NULL
    0012F394 0012F3A8 |pStartupInfo = 0012F3A8
    0012F398 0012F3EC pProcessInfo = 0012F3EC

    I do not remember that file being in my folder.
    Go to the folder where you put this target <int21h.exe> You should see a hidden file for me it is: z__70043.exe.
    And yes that is the file. Now you can work on it as you would like.
    What is interesting to note is that if you run the program and you enter an invalid password it will erase the hidden file.
    Have Fun:
    int21h

  4. #154
    پروفشنال Morteza_SOS's Avatar
    تاريخ عضويت
    Apr 2006
    پست ها
    577

    پيش فرض

    Level : beginner

    Basic disassembly on linux platform using only Objdump.
    Target is the small linux starter crackme.

    Reversing A Simple Linux App with OBJDUMP
    TARGET = here
    DIFF = Tomato ketchup its just Diff
    TOOLS USED = OBJDUMP

    Requirements

    1) I assume that you have some flavour of linux installed in your computer
    2) by prompt i mean prompt on your commandline like you@someserver:~>
    3) you have the standard binutils avl in this installation


    Let's Start
    First we will investigate this linux binary with some tools that are included in almost every distribution (binutils package). For easier reversing we will use some customized tools. Find them here.

    Ofcourse we could use IDA Pro or another commercial disassembler, but for this tuts we stick with tools that are freely available.

    The process of investigating a linux / unix binary is not that different from windows binaries. We start by doing a quick scan to see if the binary is packed/stripped, the we check its header (ELF header, not PE this time ), look for interesting strings, and finally we dig in the disassembly.

    Let's start our deadlisting...

    Binary details
    First off all we use the file command to know the details about the file we are examining

    On the prompt > type without quotes
    "file small"
    And press enter

    You will get an output in this format

    small: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV),
    for GNU/Linux 2.2.5, dynamically linked (uses shared libs), not stripped


    We come to know that this app is not stripped So most of the function calls will look like
    call &ltlibc.cout&gt
    Instead of call $0x80485634

    If it has been stripped we need to look for symbol table and Our task becomes a little more difficult



    Strings
    Ok we now look for strings inside that file

    On the prompt > type without quotes
    "strings small"
    And press enter

    You see lot of strings along with these strings in side this app


    -> Small crackme for stingduk


    Disassembling with objdump
    Ok we will look at the headers inside this file
    On the prompt > type without quotes
    " objdump -h small"
    And press enter

    The output is as follows
    small: file format elf32-i386



    Sections:
    Idx Name Size VMA LMA File off Algn



    12 .fini 0000001a 08048a94 08048a94 00000a94 2**2
    CONTENTS, ALLOC, LOAD, READONLY, CODE
    13 .rodata 000000d0 08048ac0 08048ac0 00000ac0 2**5
    CONTENTS, ALLOC, LOAD, READONLY, DATA
    14 .eh_frame_hdr 0000002c 08048b90 08048b90 00000b90 2**2
    CONTENTS, ALLOC, LOAD, READONLY, DATA
    15 .data 0000000c 08049bbc 08049bbc 00000bbc 2**2
    CONTENTS, ALLOC, LOAD, DATA
    16 .eh_frame 000000a0 08049bc8 08049bc8 00000bc8 2**2
    CONTENTS, ALLOC, LOAD, READONLY, DATA
    17 .dynamic 000000e0 08049c68 08049c68 00000c68 2**2
    CONTENTS, ALLOC, LOAD, DATA
    18 .ctors 0000000c 08049d48 08049d48 00000d48 2**2
    CONTENTS, ALLOC, LOAD, DATA
    19 .dtors 00000008 08049d54 08049d54 00000d54 2**2
    CONTENTS, ALLOC, LOAD, DATA
    20 .jcr 00000004 08049d5c 08049d5c 00000d5c 2**2
    CONTENTS, ALLOC, LOAD, DATA
    21 .got 00000038 08049d60 08049d60 00000d60 2**2
    CONTENTS, ALLOC, LOAD, DATA
    22 .bss 00000128 08049d98 08049d98 00000d98 2**3
    ALLOC
    23 .comment 000000d9 00000000 00000000 00000d98 2**0




    We need to dissemble the file now
    On the prompt > type without quotes
    " objdump -d small > dump "
    And press enter

    Open this file with cat dump | more

    If you scroll through the dump you will see the main function like I pasted below

    Though it is absolutely ok it would be better to look at the disassembly
    If we dont have those hex bytes displayed it would also be better to look at
    Disassembly if we see0xffffffff(%ebx) as -0x01(%ebx)
    Also some xrefs to data section and jump xrefs on the disassembly would also be fine
    For analyzing the disassembly easily





    804884a: c7 85 34 ff ff ff 00 movl $0x0,0xffffff34(%ebp)
    8048851: 00 00 00
    8048854: 8d 45 b8 lea 0xffffffb8(%ebp),%eax
    8048857: 03 85 34 ff ff ff add 0xffffff34(%ebp),%eax
    804885d: 80 38 00 cmpb $0x0,(%eax)
    8048860: 75 02 jne 8048864
    8048862: eb 42 jmp 80488a6
    8048864: 8d 85 38 ff ff ff lea 0xffffff38(%ebp),%eax
    804886a: 89 c1 mov %eax,%ecx
    804886c: 03 8d 34 ff ff ff add 0xffffff34(%ebp),%ecx
    8048872: 8d 45 b8 lea 0xffffffb8(%ebp),%eax
    8048875: 03 85 34 ff ff ff add 0xffffff34(%ebp),%eax
    804887b: 8a 00 mov (%eax),%al
    804887d: 66 0f be d0 movsbw %al,%dx
    8048881: 66 c7 85 26 ff ff ff movw $0xa,0xffffff26(%ebp)
    8048888: 0a 00
    804888a: 89 d0 mov %edx,%eax
    804888c: 66 99 cwtd
    804888e: 66 f7 bd 26 ff ff ff idivw 0xffffff26(%ebp)
    8048895: 88 d0 mov %dl,%al
    8048897: 83 c0 30 add $0x30,%eax
    804889a: 88 01 mov %al,(%ecx)
    804889c: 8d 85 34 ff ff ff lea 0xffffff34(%ebp),%eax
    80488a2: ff 00 incl (%eax)
    80488a4: eb ae jmp 8048854
    80488a6: 8d 85 38 ff ff ff lea 0xffffff38(%ebp),%eax



    Tools of the trade
    we use an utility called gendump that was coded by Dion Mendel
    for his prize winning honeynet reverse-engineering entry it basically uses objdump but gives a little more visually attractive display along with routines

    on the prompt > type without quotes
    "./gendump small > dump1"
    and press enter

    you will have a file called dump1 in the directory

    you can look at this file by using this command type on prompt
    cat dump1 | more

    this will output the file page by page
    I am showing here only the user code, which is denoted, by main




    # 080487bc :



    0804884a: movl $0x0,0xffffff34(%ebp)
    08048854: lea 0xffffffb8(%ebp),%eax
    08048857: add 0xffffff34(%ebp),%eax
    0804885d: cmpb $0x0,(%eax)
    08048860: jne 0x08048864
    08048862: jmp 0x080488a6
    08048864: lea 0xffffff38(%ebp),%eax
    0804886a: mov %eax,%ecx
    0804886c: add 0xffffff34(%ebp),%ecx
    08048872: lea 0xffffffb8(%ebp),%eax
    08048875: add 0xffffff34(%ebp),%eax
    0804887b: mov (%eax),%al
    0804887d: movsbw %al,%dx
    08048881: movw $0xa,0xffffff26(%ebp)
    0804888a: mov %edx,%eax
    0804888c: cwtd
    0804888e: idivw 0xffffff26(%ebp)
    08048895: mov %dl,%al
    08048897: add $0x30,%eax
    0804889a: mov %al,(%ecx)
    0804889c: lea 0xffffff34(%ebp),%eax
    080488a2: incl (%eax)
    080488a4: jmp 0x08048854
    080488a6: lea 0xffffff38(%ebp),%eax




    we also use other utility coded by Don Mendel those are
    decomp_fixup_signs
    decomp_xref_data
    decomp_xref_jumps
    the first utility will fix unwieldy 0xffffffff(%ebp)
    entries to a more readable form like -1(%ebp)
    the second utility will point the data that is being used
    like push $0x807654 will now look as
    possible reference to string "small crackme for stingduk"
    the third will show the jump references it looks easier for visualization

    on the prompt > type without quotes
    "./decomp_fixup_signs dump2"
    and press enter

    on the prompt > type without quotes
    "./decomp_xref_data small dump3 "
    and press enter

    on the prompt > type without quotes
    "./decomp_fixup_jumps dump4"
    and press enter

    after performing these you will have dump1,dump2,dump3,and dump4 files in your directory
    if you want to explore you can use cat "filename" | more to go through the contents
    I am pasting here the final content of dump4 main function




    # 080487bc :
    080487bc: push %ebp
    080487bd: mov %esp,%ebp
    080487bf: sub $0xe8,%esp
    080487c5: and $-0x10,%esp
    080487c8: mov $0x0,%eax
    080487cd: sub %eax,%esp
    080487cf: sub $0x8,%esp
    080487d2: push $0x80486d8
    080487d7: sub $0xc,%esp

    # Possible reference to rodata '-> Small crackme for stingduk
    080487e9: add $0x14,%esp
    080487ec: push %eax
    080487ed: call 0x08048658
    080487f2: add $0x10,%esp
    080487f5: sub $0x8,%esp

    # Possible reference to rodata 'Give me your name (max 50 chars): '
    080487f8: push $0x8048b00

    # Possible reference to data in bss
    080487fd: push $0x8049d98
    08048802: call 0x08048698
    08048807: add $0x10,%esp
    0804880a: sub $0x8,%esp
    0804880d: lea -0x48(%ebp),%eax
    08048810: push %eax

    # Possible reference to data in bss
    08048811: push $0x8049e28
    08048816: call 0x080486c8
    0804881b: add $0x10,%esp
    0804881e: sub $0x8,%esp

    # Possible reference to rodata 'Pass me the serial (max 50 chars): '
    08048821: push $0x8048b40

    # Possible reference to data in bss
    08048826: push $0x8049d98
    0804882b: call 0x08048698
    08048830: add $0x10,%esp
    08048833: sub $0x8,%esp
    08048836: lea -0x88(%ebp),%eax
    0804883c: push %eax

    # Possible reference to data in bss
    0804883d: push $0x8049e28
    08048842: call 0x080486c8
    08048847: add $0x10,%esp
    0804884a: movl $0x0,-0xcc(%ebp)
    08048854: lea -0x48(%ebp),%eax *
    08048857: add -0xcc(%ebp),%eax |
    0804885d: cmpb $0x0,(%eax) |
    08048860: jne 0x08048864 * |
    08048862: jmp 0x080488a6 |*|
    08048864: lea -0xc8(%ebp),%eax *||
    0804886a: mov %eax,%ecx ||
    0804886c: add -0xcc(%ebp),%ecx ||
    08048872: lea -0x48(%ebp),%eax ||
    08048875: add -0xcc(%ebp),%eax ||
    0804887b: mov (%eax),%al ||
    0804887d: movsbw %al,%dx ||
    08048881: movw $0xa,-0xda(%ebp) ||
    0804888a: mov %edx,%eax ||
    0804888c: cwtd ||
    0804888e: idivw -0xda(%ebp) ||
    08048895: mov %dl,%al ||
    08048897: add $0x30,%eax ||
    0804889a: mov %al,(%ecx) ||
    0804889c: lea -0xcc(%ebp),%eax ||
    080488a2: incl (%eax) ||
    080488a4: jmp 0x08048854 |*
    080488a6: lea -0xc8(%ebp),%eax *
    080488ac: add -0xcc(%ebp),%eax
    080488b2: movb $0x0,(%eax)
    080488b5: lea -0x88(%ebp),%eax
    080488bb: lea -0xc8(%ebp),%edx
    080488c1: sub $0x8,%esp
    080488c4: push %eax
    080488c5: push %edx
    080488c6: call 0x08048668
    080488cb: add $0x10,%esp
    080488ce: test %eax,%eax
    080488d0: jne 0x080488fa *
    080488d2: sub $0x8,%esp |
    080488d5: push $0x80486d8 |
    080488da: sub $0xc,%esp |

    # Possible reference to rodata 'Great work!'
    080488dd: push $0x8048b64 |

    # Possible reference to data in bss
    080488e2: push $0x8049d98 |
    080488e7: call 0x08048698 |
    080488ec: add $0x14,%esp |
    080488ef: push %eax |
    080488f0: call 0x08048658 |
    080488f5: add $0x10,%esp |
    080488f8: jmp 0x08048920 *|
    080488fa: sub $0x8,%esp |*
    080488fd: push $0x80486d8 |
    08048902: sub $0xc,%esp |

    # Possible reference to rodata 'No luck here mate :('
    08048905: push $0x8048b70 |

    # Possible reference to data in bss
    0804890a: push $0x8049d98 |
    0804890f: call 0x08048698 |
    08048914: add $0x14,%esp |
    08048917: push %eax |
    08048918: call 0x08048658 |
    0804891d: add $0x10,%esp |
    08048920: mov $0x0,%eax *
    08048925: leave
    08048926: ret
    08048927: nop






    Analysis
    well we can now analyze the executable and see how it works we notice init is called after every push of a string so we can safely assume this to be a printf or cout function this takes a format parameter and input parameter and prints to stderr

    yes we see there are two pushes to each of the call one is a string and other is from bss section which would be the format like %X,%c,%s etc

    ok we leave it at it now and go down to a place where it we have entered our serial we see a loop starting from 8048854




    0804884a: movl $0x0,-0xcc(%ebp) ;moves 0 in [ebp-0xcc]
    08048854: lea -0x48(%ebp),%eax * ;loads address of name string
    08048857: add -0xcc(%ebp),%eax | ;well effectively adds 0 [ebp-0xcc] to eax
    0804885d: cmpb $0x0,(%eax) | ;tests if eax contains 0
    08048860: jne 0x08048864 * | ;if not 0 jumps to 64 else go down
    08048862: jmp 0x080488a6 |*| ;basically jumps to end of loop
    08048864: lea -0xc8(%ebp),%eax *|| ;loads address in [ebp-0xc8] strlength
    0804886a: mov %eax,%ecx || ;moves the content of eax to ecx
    0804886c: add -0xcc(%ebp),%ecx || ;adds 0 to ecx in first round [ebp-0xcc] = 0
    08048872: lea -0x48(%ebp),%eax || ;loads address in [ebp-0x48] to eax
    08048875: add -0xcc(%ebp),%eax || ;adds 0 to eax in first round [ebp-0xcc] = 0
    0804887b: mov (%eax),%al || ;eax will become equal to al
    0804887d: movsbw %al,%dx || ;moves the content of al to dx
    08048881: movw $0xa,-0xda(%ebp) || ;moves 0xa to [ebp-0xda]
    0804888a: mov %edx,%eax || ;moves contents of edx to eax
    0804888c: cwtd || ; preparing for division
    0804888e: idivw -0xda(%ebp) || ;divides eax by [ebp-0xda] == eax/0xa(10 dec)
    08048895: mov %dl,%al || ;moves remainder of the above division to al
    08048897: add $0x30,%eax || ;adds 0x30 to remainder of division
    0804889a: mov %al,(%ecx) || ;moves the (remainder+0x30) to ecx
    0804889c: lea -0xcc(%ebp),%eax || ;well effectively adds 0 [ebp-0xcc] to eax
    080488a2: incl (%eax) || ;adds 1 to [eax] == [ebp-0xcc]
    080488a4: jmp 0x08048854 |* ;jumps back to start of loop
    080488a6: lea -0xc8(%ebp),%eax *





    so we can safely assume the serial calculation routine is
    == ((chars in name string % 0xa)+0x30)
    and when all chars are done it jumps to 080488a6: lea -0xc8(%ebp),%eax *
    here is the comparison routine




    080488a6: lea -0xc8(%ebp),%eax ;loads eax with [ebp_0xc8]
    080488ac: add -0xcc(%ebp),%eax ;adds eax with [ebp_0xc8]
    080488b2: movb $0x0,(%eax) ;appends null terminator to calculated hash
    080488b5: lea -0x88(%ebp),%eax ;loads eax with [ebp-0x88]
    080488bb: lea -0xc8(%ebp),%edx ;loads edx with [ebp-0xc8]
    080488c1: sub $0x8,%esp
    080488c4: push %eax
    080488c5: push %edx
    080488c6: call 0x08048668 ;must be strcmp
    080488cb: add $0x10,%esp
    080488ce: test %eax,%eax ;test
    080488d0: jne 0x080488fa ;good guy bad guy jump





    Outtro
    Till now this was all about deadlisting and analyzing the executable without running it
    now we will run the gnu debugger gdb and do a live debugging on the executable in the second part
    of this tutorial keep looking

  5. #155
    پروفشنال Morteza_SOS's Avatar
    تاريخ عضويت
    Apr 2006
    پست ها
    577

    پيش فرض

    Level : beginner

    Manually unpacking PEid v0.93



    It was 10:39 at night,when I decided to see what kind of API's PEid v.093 used
    because I was curious about some stuff.Unfortunatelly,this version of PEid is
    protected by a protector.So,I opened another version of PEid and identified the packer
    as SPLayer 0.08 -> Jibz.


    Now only tools needed are: Olly v1.10,OllyDump Plugin,command line plugin,ImpRec v1.6f


    Open the PEid (target) using Olly and u are at the Entry Point here:


    00425FDA > ? 8D40 00 LEA EAX,DWORD PTR DS:[EAX]
    00425FDD . B9 CC5F4200 MOV ECX,PEiD.00425FCC
    00425FE2 . 6A 0E PUSH 0E
    00425FE4 . 58 POP EAX
    00425FE5 > C00C01 04 ROR BYTE PTR DS:[ECX+EAX],4
    00425FE9 . 48 DEC EAX
    00425FEA .^75 F9 JNZ SHORT PEiD.00425FE5



    Now,in exceptions be sure that you have checked only ignore memory access violations in KERNEL32.
    Press Shift+F9 one time,and Olly breaks at an exception,here:


    00401016 89 DB 89
    00401017 08 DB 08
    00401018 50 DB 50 ; CHAR 'P'
    00401019 45 DB 45 ; CHAR 'E'
    0040101A 43 DB 43 ; CHAR 'C'
    0040101B 32 DB 32 ; CHAR '2'
    0040101C 00 DB 00
    0040101D 8E DB 8E
    0040101E E0 DB E0



    Now,press the "M" buttont in Olly,and you can see the Image of memory.Right click and
    set break-on-acess at code section (.text).Now press Shift+F9 once more and the
    breakpoint is triggered,Olly pauses at code section,here:



    00479599 C602 E9 MOV BYTE PTR DS:[EDX],0E9
    0047959C 83C2 05 ADD EDX,5
    0047959F 2BCA SUB ECX,EDX
    004795A1 894A FC MOV DWORD PTR DS:[EDX-4],ECX
    004795A4 33C0 XOR EAX,EAX
    004795A6 C3 RETN


    Now start tracing using F7 and execute the RETN,and you are at windows API's
    memory here:


    77F79BA4 64:8B25 00000000 MOV ESP,DWORD PTR FS:[0]
    77F79BAB 64:8F05 00000000 POP DWORD PTR FS:[0]
    77F79BB2 8BE5 MOV ESP,EBP
    77F79BB4 5D POP EBP
    77F79BB5 C2 1400 RETN 14



    Well,if u continue tracing with F7,the code will lead to an opcode like this:



    7FFE0300 8BD4 MOV EDX,ESP
    7FFE0302 0F34 SYSENTER ; Jamps at kernel,Ring-3 debuggers cannot proceed debugging



    This opcode will jamp at kernel,where Olly as a Ring-3 debugger cannot proceed the
    debugging,and will just run the exe,bypassing the OEP where we need to land.So set
    again a break-on-access breakpoint when being at 77F79BA4,in code (.text) section and
    press Shift+F9 one more time and we land here:



    00401016 .-E9 8C850700 JMP PEiD.004795A7



    Trace the JMP using F7 and we land Here:


    004795A7 B8 6884BAFF MOV EAX,FFBA8468
    004795AC 64:8F05 00000000 POP DWORD PTR FS:[0]
    004795B3 83C4 04 ADD ESP,4
    004795B6 55 PUSH EBP
    004795B7 53 PUSH EBX
    004795B8 51 PUSH ECX
    004795B9 57 PUSH EDI
    004795BA 56 PUSH ESI
    004795BB 52 PUSH EDX
    004795BC 8D98 F8108D00 LEA EBX,DWORD PTR DS:[EAX+8D10F8]



    Now trace till 004795BC.Those pushes you see,are the basic register pushes that a packer
    saves in stack,then executes its code and at the end pops them back from stack and jamps at OEP.
    So,when you are at 004795BC,go to ESP register and right click->Follow in Dump.In Dump window
    you see this:


    0012FFAC 04 03 FE 7F D5 BB 12 00 F7 03 00 00 00 00 00 00 þÕ».÷......
    0012FFBC 00 F0 FD 7F F0 FF 12 00 C7 14 E8 77 F7 03 00 00 .ðýðÿ.Çèw÷..
    0012FFCC D4 BB 12 00 00 F0 FD 7F F0 DC B1 F1 C8 FF 12 00 Ô»..ðýðܱñÈÿ.
    0012FFDC 8F C8 53 80 FF FF FF FF 09 48 E9 77 10 12 E9 77 ÈS€ÿÿÿÿ.Héwéw
    0012FFEC 00 00 00 00 00 00 00 00 00 00 00 00 DA 5F 42 00 ............Ú_B.
    0012FFFC 00 00 00 00 ....



    Now highlight the four bytes at 0012FFAC (04 03 FE 7F) and right click->Breakpoint->
    Hardware on access->Dword.This will trigger Olly to pause when ESP has the same
    value as now (0012FFAC).This will happen when the basic registers will be poped
    and just before the Magic jamp at OEP.This trick can be used in many simple
    packers,but of cource NOT all packers.


    Now press one more time Shift+F9 and the breakpoint is triggered,we land here:



    0047964A 5E POP ESI ; PEiD.00455F1E
    0047964B 5F POP EDI
    0047964C 59 POP ECX
    0047964D 5B POP EBX
    0047964E 5D POP EBP
    0047964F FFE0 JMP EAX



    Remove hardware breakpoint.So,you are at 0047964A,trace a little more using F7 and the
    magic jamp at 0047964F goes you at OEP,so execute it and we land here:


    00455F1E 6A DB 6A ; CHAR 'j'
    00455F1F 60 DB 60 ; CHAR '`'
    00455F20 68 DB 68 ; CHAR 'h'
    00455F21 08 DB 08
    00455F22 F5 DB F5
    00455F23 42 DB 42 ; CHAR 'B'
    00455F24 00 DB 00
    00455F25 E8 DB E8
    00455F26 B2 DB B2



    We cannot see the code,so right click on it->Analysis->Analyze code.You see that:



    00455F1E . 6A 60 PUSH 60
    00455F20 . 68 08F54200 PUSH PEiD.0042F508
    00455F25 . E8 B2180000 CALL PEiD.004577DC
    00455F2A . BF 94000000 MOV EDI,94
    00455F2F . 8BC7 MOV EAX,EDI
    00455F31 . E8 1AFAFFFF CALL PEiD.00455950
    00455F36 . 8965 E8 MOV DWORD PTR SS:[EBP-18],ESP
    00455F39 . 8BF4 MOV ESI,ESP
    00455F3B . 893E MOV DWORD PTR DS:[ESI],EDI
    00455F3D . 56 PUSH ESI ; /pVersionInformation
    00455F3E . FF15 90114000 CALL DWORD PTR DS:[401190] ; GetVersionExA
    00455F44 . 8B4E 10 MOV ECX,DWORD PTR DS:[ESI+10]



    So OEP=00455F1E.Now dump the process using OllyDump,without having Import Rebuilding Option
    checked.Now open ImpRec,select the process and enter as OEP=OEP as seen in Olly-Imagebase=
    00455F1E-00400000=00055F1E.Then IAT Autoseach and Get Imports.Now press Show invalid.Good,no
    Invalid thunks,so proceed and Fix Dump.


    Now go for it,and run the fixed dump.Wow,it runs just fine.Target Unpacked!


    Have in mind that if U ran the fixed dumped exe under Olly,it will check if there is
    a Debugger using IsDebuggerPresent API.So you should either have OllyHide Plugin
    or just place a breakpoit at IsDebuggerPresent,and when Olly breaks,trace till
    user code and make EAX=0.

  6. #156
    پروفشنال Morteza_SOS's Avatar
    تاريخ عضويت
    Apr 2006
    پست ها
    577

    پيش فرض

    Level : intermediate

    How to rebuild an IAT from scratch using ImpRec.

    $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
    $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
    $$$$$$$$$$$$$$$$$$ RebuilDing IAT From Scratch Using ImpRec Tutorial by KaGra $$$$$$$$$$$$$$$$$$$$
    $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
    $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$



    Tools used: ImpRec and Olly v1.10

    This is a tutorial about rebuilding the IAT in unpacked exe files that their
    table has been completelly destroyed but the packer-protector.An example of
    such packers are Armadillo and SDprotector.I assume that U know tha basics
    so I won't say much of details.

    Well,ImpRec has a great feature that is called Load-Save tree.U enter the general
    structure of the IAT u want Imprec to create in a txt file,and with Load Tree U
    can inject this in the exe.Then Imprec will create this IAt.The save tree dumpes in
    a txt file the current IAT of the exe,so U can make modifications and Load it back
    again,or do anything U like.

    Assume we have a simple exe (in zip,is simple.exe).Just run it,open ImpRec and
    select IAT autosearch and the Get imports.Then,Save tree to dump the IAT in a txt.
    Now open the txt.I will explain to U the basic format of it,so U can change anything
    U may want (I saved it as simple.txt in zip):



    Target: Cocuments and SettingsasdDesktopsimple.exe
    OEP: 00001000 IATRVA: 00002000 IATSize: 00000058

    FThunk: 00002000 NbFunc: 00000003
    1 00002000 kernel32.dll 016F GetModuleHandleA
    1 00002004 kernel32.dll 03A0 lstrcmp
    1 00002008 kernel32.dll 00B0 ExitProcess

    FThunk: 00002010 NbFunc: 00000011
    1 00002010 user32.dll 0061 CreateWindowExA
    1 00002014 user32.dll 008F DefWindowProcA

    bla...bla...bla...




    Well,OEP is the Original Entry Point,IAT RVA is the virtual address where the start of
    the IAT in the exe is and IAT size,what it sais.First number after FThunk string is
    the RVA of the first API in IAT,for the API os this same dll and the NbFunc is the
    number of all APIs in this dll.After the line of FThunk string,are lines that describe
    the API's.The first number (here is 1) says that API is valid (check simple.txt for
    more info about it).The second number is the Virtual address that fills with the
    Address of the first opcode of the API that a line of this txt is reffering to.The
    next is a string that says which dll has this API code,the next number is a number
    that makes as to know the relative position of this API,in the IAT and among all
    other API's inside IAT and finally the last is the string name of the API.

    Let us see the IAT of simple.exe now,then take a line from the simple.txt and
    see how those things described in a line of txt can be seen in the exe.So,the IAT
    of simple.txt is that (.rdata section in Olly's memory image):



    00402000 >86 AD E7 77 EC 5D E7 77 FD 98 E7 77 00 00 00 00 †­çwì]çwý˜çw....
    00402010 >26 8B D4 77 55 5C D4 77 81 43 D4 77 DC 79 D4 77 &‹ÔwUÔwCÔwÜyÔw
    00402020 >0A 1A D6 77 8F 43 D4 77 17 60 D4 77 81 9C D4 77 .ÖwCÔw`ÔwœÔw
    00402030 >24 97 D4 77 76 64 D6 77 E9 B9 D4 77 92 BD D4 77 $—ÔwvdÖwé¹Ôw’½Ôw
    00402040 >03 6E D5 77 05 79 D4 77 14 79 D4 77 FA 3D D4 77 nÕwyÔwyÔwú=Ôw
    00402050 >89 5B D4 77 00 00 00 00 00 00 00 00 00 00 00 00 ‰[Ôw............
    00402060 00 00 00 00 3B 27 F9 3C 00 00 00 00 01 00 00 00 ....;'ù<.......
    00402070 15 0B 00 00 00 00 00 00 00 1E 00 00 00 00 00 00  .............
    00402080 3B 27 F9 3C 00 00 00 00 04 00 00 00 10 01 00 00 ;'ù<.........
    00402090 00 00 00 00 18 29 00 00 00 00 00 00 00 00 00 00 ....)..........
    004020A0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    004020B0 00 00 00 00 F0 20 00 00 00 00 00 00 00 00 00 00 ....ð ..........
    004020C0 76 21 00 00 00 20 00 00 00 21 00 00 00 00 00 00 v!... ...!......
    004020D0 00 00 00 00 A2 22 00 00 10 20 00 00 00 00 00 00 ....¢".. ......
    004020E0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    004020F0 56 21 00 00 6A 21 00 00 48 21 00 00 00 00 00 00 V!..j!..H!......
    00402100 84 21 00 00 96 21 00 00 A8 21 00 00 BC 21 00 00 „!..–!..¨!..¼!..
    00402110 CC 21 00 00 DE 21 00 00 EC 21 00 00 00 22 00 00 Ì!..Þ!..ì!..."..
    00402120 0E 22 00 00 1A 22 00 00 28 22 00 00 3A 22 00 00 ".."..("..:"..
    00402130 4E 22 00 00 60 22 00 00 70 22 00 00 7E 22 00 00 N"..`"..p"..~"..
    00402140 92 22 00 00 00 00 00 00 75 00 45 78 69 74 50 72 ’"......u.ExitPr
    00402150 6F 63 65 73 73 00 11 01 47 65 74 4D 6F 64 75 6C ocess.GetModul
    00402160 65 48 61 6E 64 6C 65 41 00 00 D6 02 6C 73 74 72 eHandleA..Ölstr
    00402170 63 6D 70 41 00 00 4B 45 52 4E 45 4C 33 32 2E 64 cmpA..KERNEL32.d
    00402180 6C 6C 00 00 58 00 43 72 65 61 74 65 57 69 6E 64 ll..X.CreateWind
    00402190 6F 77 45 78 41 00 83 00 44 65 66 57 69 6E 64 6F owExA.ƒ.DefWindo
    004021A0 77 50 72 6F 63 41 00 00 94 00 44 69 73 70 61 74 wProcA..”.Dispat
    004021B0 63 68 4D 65 73 73 61 67 65 41 00 00 B6 00 45 6E chMessageA..¶.En
    004021C0 61 62 6C 65 57 69 6E 64 6F 77 00 00 02 01 47 65 ableWindow..Ge
    004021D0 74 44 6C 67 49 74 65 6D 54 65 78 74 41 00 28 01 tDlgItemTextA.(
    004021E0 47 65 74 4D 65 73 73 61 67 65 41 00 43 01 47 65 GetMessageA.CGe
    004021F0 74 53 79 73 74 65 6D 4D 65 74 72 69 63 73 00 00 tSystemMetrics..
    00402200 97 01 4C 6F 61 64 43 75 72 73 6F 72 41 00 9B 01 —LoadCursorA.›
    00402210 4C 6F 61 64 49 63 6F 6E 41 00 BB 01 4D 65 73 73 LoadIconA.»Mess
    00402220 61 67 65 42 6F 78 41 00 DD 01 50 6F 73 74 51 75 ageBoxA.ÝPostQu
    00402230 69 74 4D 65 73 73 61 67 65 00 EF 01 52 65 67 69 itMessage.ïRegi
    00402240 73 74 65 72 43 6C 61 73 73 45 78 41 00 00 28 02 sterClassExA..(
    00402250 53 65 74 44 6C 67 49 74 65 6D 54 65 78 74 41 00 SetDlgItemTextA.
    00402260 56 02 53 65 74 57 69 6E 64 6F 77 50 6F 73 00 00 VSetWindowPos..
    00402270 65 02 53 68 6F 77 57 69 6E 64 6F 77 00 00 7D 02 eShowWindow..}
    00402280 54 72 61 6E 73 6C 61 74 65 4D 65 73 73 61 67 65 TranslateMessage
    00402290 00 00 8B 02 55 70 64 61 74 65 57 69 6E 64 6F 77 ..‹UpdateWindow
    004022A0 00 00 55 53 45 52 33 32 2E 64 6C 6C 00 00 00 00 ..USER32.dll....


    Let's take a line from the simple.txt file:


    1 00002008 kernel32.dll 00B0 ExitProcess


    So,this line says thet the address of this API is at 00002008 (+ImageBase=00400000) so
    lets look at 00402008,there are those strings:

    FD 98 E7 77


    Inreverse,this is the start of code of ExitProcess,check it in Olly doing a search
    at all modules name (well,your numbers may be different because of the version of
    Windows,but still pointing at ExitProcess).ExitProcess belongs to kernel32.dll as U
    also can see in Olly.The final value of 00B0 is the same for every IAT txt dump that
    U will make in your system,in every exe.Don't change this.It just is an ID in case we
    don't want to declare a name for the API.Just let it be the same that is at any exe IAT
    dump.

    Ok.Assume now that U have the dump of an exe,U have the OEP and manually U have
    traced and found what calls are made to APIs.But there is not any valid IAT,and Imprec
    doesn't find any imports to validate.If there is not an IAT at all,meaning that all the above
    IAT from 00402000 are filled with 00's,then Imprec doesn't give U anyhing to fix manually.So,
    just assume U have the following code of the exe (it is target.exe in zip):


    00401000 > $ 6A 00 PUSH 0
    00401002 . 68 04204000 PUSH dumped.00402004 ; ASCII "Hey man "
    00401007 . 68 0F204000 PUSH dumped.0040200F ; ASCII "Try to Run Me under Olly or See APIs using WinDasm"
    0040100C . 6A 00 PUSH 0
    0040100E . E8 0D000000 CALL dumped.00401020
    00401013 . 6A 00 PUSH 0
    00401015 . E8 00000000 CALL dumped.0040101A
    0040101A FF25 4C304000 JMP DWORD PTR DS:[40304C]
    00401020 FF25 54304000 JMP DWORD PTR DS:[403054]




    Now,assume U know that the first call goes at MessageBoxA and the second at ExitProcess.U can
    also see the section where tha IAT should have been:


    00403000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    00403010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    00403020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    00403030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    00403040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    00403050 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    00403060 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    00403070 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................


    So,U have to create a txt file,with the proper format and load it in ImpRec.So,U have
    OEP=00001000 and IATRVA=00002000 and u can choose any size (big enough though to fit the
    new IAT).Choose also the RVA's of the addresses of API's U like.Generally,a good idea is to
    just dump from a known exe and IAT in a txt with Imprec,find those API's U are interested
    to fix in new exe,and erase all the others,fixing also the RVA's properelly to your
    section where the IAT is to be created.Do,in our case,a good txt file is:


    Target: Cocuments and SettingsasdDesktopdumped.exe
    OEP: 00001000 IATRVA: 00003000 IATSize: 00000070


    FThunk: 0000304C NbFunc: 00000001
    1 0000304C kernel32.dll 00B0 ExitProcess

    FThunk: 00003054 NbFunc: 00000001
    1 00003054 user32.dll 010E MessageBoxA



    Now,load it as tree in ImpRec and Fix the dump.Open the new fixed exe and see the new Import
    that is created by ImpRec:


    00405000 00 00 00 00 00 00 00 00 00 00 00 00 3C 50 00 00 ............<P..
    00405010 4C 30 00 00 00 00 00 00 00 00 00 00 00 00 00 00 L0..............
    00405020 58 50 00 00 54 30 00 00 00 00 00 00 00 00 00 00 XP..T0..........
    00405030 00 00 00 00 00 00 00 00 00 00 00 00 6B 65 72 6E ............kern
    00405040 65 6C 33 32 2E 64 6C 6C 00 00 B0 00 45 78 69 74 el32.dll..°.Exit
    00405050 50 72 6F 63 65 73 73 00 75 73 65 72 33 32 2E 64 Process.user32.d
    00405060 6C 6C 00 00 0E 01 4D 65 73 73 61 67 65 42 6F 78 ll..MessageBox
    00405070 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 A...............



    Althought IATRVA was 00003000,the fixed has RVA=00005000,because we have checked in
    ImpRec to create a new section for IAT,don't mind.It's working just fine.

    Have in your mind that the jamps in code section,at 0040101A may also have been
    erased from packer,and U may have either to write them as code after IAT rebuilding
    or just create a way to emulate them,at any part of your code or other section U may
    create.

  7. #157
    پروفشنال Morteza_SOS's Avatar
    تاريخ عضويت
    Apr 2006
    پست ها
    577

    پيش فرض

    Level : intermediate

    How you can block a Ring level 3 debugger.

    See this tutor using notepad,Font Fixedsys Regular,size 10



    Well,since my last Tutor many packerz got into my handz.And I should say that
    the only one I saw having a Ring-3 Debugger Blocker is Armadillo.But why does not
    the otherz use this wonderfull feature?The answer is I DON'T KNOW.

    Well,creating such a feature is not difficult.The general idea is this:

    Olly, (which is Ring-3) when we load an exe in her,locates dlls that the exe
    will use (actually,will use the API's in those dll's) from their names in the
    Import Address Table.Then,loads those dll's in memory that is also now being
    allocated for this purpose.After that,fills the IAT with the API's addresses
    that reside in the mentioned loaded dll's.The thing is that if we run this exe
    now,and this exe creates a new proccess,Olly will not be able to breakpoint at
    any API that is being used from this second process (although those API's are
    part of the SAME dll code that has been allocated from the first loaded exe).And
    this is because the allocated space that contains the API's (and dll's) is only
    a copy of the original,and not the original dll memory space,because it is
    a RinG-3 debugger.So,the new process created by the first exe will allocate
    its own memory space from windows loader and will call from there the API's and
    not from the allocated by Olly (Olly playz actually the windows loader for
    the first exe).So,putting any kind of breakpoint in Olly (software or hardware)
    will NOT trigger the API's that are called from the second proccess,thus making
    Olly useless.

    The procedure to follow is simple:

    a) The original exe creates a process of itself.
    b) Patches itself in memory,because if not then the new process will create another
    one,and this another one etc. etc.
    c) The process of the original exe (father) exits
    d) Now the second proccess (child) continues running and Olly cannot
    breakpoint on it.



    These API's will be used in order to create the first original exe (the exe anyway):



    1) CreateProcessA => To create the new proccess (child) ,which is actually a copy of the father

    2) WriteProcessMemory => To patch the first process

    3) ResumeThread => After patching child continues to execute and is Free!

    4) MessageBoxA => This is actually the usefull code of the prog and cannot be
    breakpointed from Olly.
    5) ExitProcess => To exit the process



    HeRe follows the source code of the exe:


    00401000 >/$ 68 80204000 PUSH father.00402080 ; /pProcessInfo = father.00402080
    00401005 |. 68 38204000 PUSH father.00402038 ; |pStartupInfo = father.00402038
    0040100A |. 6A 00 PUSH 0 ; |CurrentDir = NULL
    0040100C |. 6A 00 PUSH 0 ; |pEnvironment = NULL
    0040100E |. 6A 04 PUSH 4 ; |CreationFlags = CREATE_SUSPENDED
    00401010 |. 6A 00 PUSH 0 ; |InheritHandles = FALSE
    00401012 |. 6A 00 PUSH 0 ; |pThreadSecurity = NULL
    00401014 |. 6A 00 PUSH 0 ; |pProcessSecurity = NULL
    00401016 |. 6A 00 PUSH 0 ; |CommandLine = NULL
    00401018 |. 68 2D204000 PUSH father.0040202D ; |ModuleFileName = "father.exe"
    0040101D |. E8 46000000 CALL <JMP.&KERNEL32.CreateProcessA> ; CreateProcessA
    00401022 |. B8 00104000 MOV EAX,father.<ModuleEntryPoint>
    00401027 |. 6A 00 PUSH 0 ; /pBytesWritten = NULL
    00401029 |. 6A 05 PUSH 5 ; |BytesToWrite = 5
    0040102B |. 68 90204000 PUSH father.00402090 ; |Buffer = father.00402090
    00401030 |. 50 PUSH EAX ; |Address => 401000
    00401031 |. FF35 80204000 PUSH DWORD PTR DS:[402080] ; |hProcess = NULL
    00401037 |. E8 38000000 CALL <JMP.&KERNEL32.WriteProcessMemory> ; WriteProcessMemory
    0040103C |. FF35 84204000 PUSH DWORD PTR DS:[402084] ; /hThread = NULL
    00401042 |. E8 27000000 CALL <JMP.&KERNEL32.ResumeThread> ; ResumeThread
    00401047 |. 6A 00 PUSH 0 ; /ExitCode = 0
    00401049 . E8 2C000000 CALL <JMP.&KERNEL32.ExitProcess> ; ExitProcess
    0040104E . 6A 00 PUSH 0 ; /Style = MB_OK|MB_APPLMODAL
    00401050 . 68 04204000 PUSH father.00402004 ; |Title = "hay :-)"
    00401055 . 68 0C204000 PUSH father.0040200C ; |Text = "Did I secapEd frOm YoUr BPx s???"
    0040105A . 6A 00 PUSH 0 ; |hOwner = NULL
    0040105C . E8 1F000000 CALL <JMP.&USER32.MessageBoxA> ; MessageBoxA
    00401061 . 6A 00 PUSH 0 ; /ExitCode = 0
    00401063 . E8 12000000 CALL <JMP.&KERNEL32.ExitProcess> ; ExitProcess



    At 0040101D it creates a new process which is a copy of the same exe,and pauses (SUSPENDS)
    the execution of it.At 00401037 patches the second process at 00401000 with the opcode
    JMP 0040104E.So,now the second process has the same code as the first (father) with the
    only changed opcode the first at 00401000.At 00401042 the second (child) process continues
    to execute (actually,now starts from 00401000).The father then terminates at 00401049,and
    the child starting from 00401000,it jamps at 0040104E,and the messagebox pops up.If u place
    a hardware of software or any other kind of breakpoint to MessageBoxA API (whenever u like
    it doesn't matter) the API will not be triggered,and any other code may follow after 0040104E.


    But what if we open a second Olly and attach to the child proccess?Well,do that and child is
    not appearing in the tasks list to attach!So,we cannot attach!The child also cannot be
    seen from LordPE.


    How can this be defeated?Well,the first way is to make somehow the child to appear in the
    attach list somehow (or any other attach list with more advanced dumping toolz) and the
    second is to place a direct jamp at the "useful" code (here at 0040104E).


    Well,u can also defeat those two.The first can be defeated by creating many many childs and
    patching that way,that after the xxx child,will run the useful code.This will make attaching
    in process (if anyone manages doing it) very irritating,since he has to do this many times.The
    second can be defeated by using large garbadge and code of encryption of any kind.U can also
    use code to check if the previouly childs have really run (because if someone patches with
    jamps,the child(s) will not run).This is done by checking if there are actually modifications
    of code,and will be if child(s) have run,due to the use of WriteProcessMemory.




    BoNus: Another small trick to block debuggers and Dasm's

    Load the bug.exe in Olly.What?Cannot be loaded.Try to see it's contents in WinDasm.What?
    Cannot see the API calls.Now check the header using a hex editor,and see those two values:

    LoaderFlags: EDABDDCA
    NumberOfRvaAndSizes: BBDCBDFA

    Well,because of those two values that are false,the tools are being confused.Change them
    to LoaderFlags=0 and NumberOfRvaAndSizes=10h (common values for almost all exe's) and the exe
    loads just fine in Olly and Dasm now shows the API calls.File was not packed or any other
    kind protected as u may have assumed at first.This works by changing BOTH of them.


    Well,this is the end of that.U can make the-ThinG routine much more sophisticated
    using debugging API's.See MSDN library and U will get what I mean...


    This is the end of it.

  8. #158
    پروفشنال Morteza_SOS's Avatar
    تاريخ عضويت
    Apr 2006
    پست ها
    577

    پيش فرض

    A little guide for wannabe cracker/reverser.

    by Zephyrous/BiW-Reversing


    1. Introduction

    Hello wannabe cracker/reverser.
    if you read this text, i assumed you're zero knowledge in reversing/cracking.
    but i dont guarantee you'll become a reverser after reading this text.
    btw, in reversing, there is no quickstart to be a good reverser.
    but, this guide tends to be a quickstart for you if really want to be a reverser.
    you must ready to take a lot pains and great pleasure too (after you find the true path).
    there are two term in this lore, reversing and cracking. but it's not same.
    not all crackers are reversers but all reversers are crackers.


    First at all, i want to warn you before started to read this guide. IMHO, to be a
    reverser, its not a good way if you going deep directly to the subject without any
    programming language knowledge especially the higher level language like C, C++,
    Pascal or even BASIC. It is because most of our target are not written in assembly,
    thus the perfect programming language that need to be learnt before reversing
    is C. The C programming language is slightly higher level than the
    computer core language, assembly language (translated machine language).
    Fortunately, C is just a small programming language and not too hard to be learnt.
    I guess it take just in 21 days :P. Go learn C and then come back again.

    I am by myself, not an expert in this subject. Be honest, i am just slightly
    above from beginner level. So, we could assume this guide is 'from a beginner to beginners'.
    Therefore, i could understand what are the problems of reversing in beginning days.
    I hope the readers could understand easily this text.

    The basic of reversing or some people call it 'reverse code engineering' is
    investigation of compiled binary computer codes or machine codes.
    in the early of computer era, computer programs are written by 'hand'. no compiler
    exist in the days. the programmer must learn & know the internal languague of any computer
    they want to program. the process is very pain and very buggy.
    so they though about a compiler to translate human language to computer language.

    And today, most computer programs are compiled or at least assembled. thus, the
    task will be taken by reverser is to study the compiled or assembled (both in binary)
    by disassembling the binary code using a disassembler.

    the binary is in 0 and 1 digit maybe look like 100100100101010010101010010100001100111001

    its very hard to be read so hexadecimal number being used for easier reading.
    hexa number base on 16 digit, 0,1,2,3,4,....,9,A,B,C,D,E,F

    817D 0C 10010000 <-- 10000001011111010000110000010000000000010000000000 000000
    75 2A <-- 111010100101010
    68 C8000000 <-- 110100011001000000000000000000000000000

    the code above is converted to hexa, because its more readable than binary number
    and below is the mnemonix of the intel processor's opcodes.

    CMP DWORD PTR SS:[EBP+C],110 ; 81h is opcode for mnemonix cmp (compare)
    JNZ 00002A ; 75h is opcode for mnemonix jnz (jump not zero)
    PUSH 0C8 ; 68h is opcode for mnemonix push (push)

    * opcodes are computer instruction in binary digit(bit).
    ** xxh - h mean in hexadecimal, sometimes we use 0x prefix for hexa number
    example: 0xFF1A

    assembly language is computer nature language but the computer still cant understand
    because its just mnemonix code and still readable by human. thats why,
    codes in assembly lang. must be assembled to binary opcodes or machine codes.

    in this guide, i wont tell you how to convert binary to decimal or to hexa or vice versa
    manually. you simply can ask your maths teacher or just google to find the tutes.
    it is because we have all have calc.exe to do the jobs. but the knowledge is knowledge
    and knowledge is power. you should learn how to convert the base number later.


    2. The power of Assembly

    in cracking or reversing, we dont reverse the machine code but the disassembled machine
    codes in assembly language. so, just forget about this course if you dont want to learn
    it or too lazy to learn a new programming language.

    since machine codes is formed by binary digit (bit), we should take a lesson how the bit is
    formed. because bit is special number, it must be aligned because of it natures.
    They are bits, nibbles, bytes, word, dword.

    example
    --------|-----------------------|-----------------------------------|
    bit | a digit, 0 or 1 | 0 or 1 |
    --------|-----------------------|-----------------------------------|
    nibble | four bits, | 1111, 1001 |
    --------|-----------------------|-----------------------------------|
    byte | eight bits, | 11111111 |
    --------|-----------------------|-----------------------------------|
    word | sixteen bits | 1111111111111111 |
    --------|-----------------------|-----------------------------------|
    dword | thirty-two bits | 11111111111111111111111111111111 |
    --------|-----------------------|-----------------------------------|

    most at all, bits are aligned using bytes or 8 bits. why?
    i'll show you something

    Nibbles:

    hexadecimal | binary | decimal
    ---------------------------------
    0 0000 0
    1 0001 1
    2 0010 2
    3 0011 3
    4 0100 4
    5 0101 5
    6 0110 6
    7 0111 7
    8 1000 8
    9 1001 9
    A 1010 10
    B 1011 11
    C 1100 12
    D 1101 13
    E 1110 14
    F 1111 15

    from above you could see a nible can transform up to 16 number from 0h to Fh
    or from 0 to 15 in decimal. meditate by yourself why hexadecimal number is
    chosen instead of decimal number to REPRESENT the binary number.

    by the way, byte is using double of nibble's bits, 11111111 == 0xFF == 255
    from 0 to 0xFF ..... 0 to 11111111 ..... 0 to 255.
    a 256 combination including 0 of numbers, a byte is enough for replacing
    ascii characters in binary.

    now run your calc.exe with scientific mode.. try to play with base number.

    so, 8 bits (byte) number are 0 -> 0xFF, 16 bits(word) numbers are 0 -> 0xFFFF
    and 32 bits (dword) 0 -> 0xFFFFFFFF.

    Notes:
    (2^32) - 1 == 0xFFFFFFFF

    i assumed you use intel compatible processor now. and it is a 32 bits processor.
    32 bits technology by today pentium 4 is came from ancient 386 processor.
    but, do you know what the hell 32 bits thingy played around with the processor?
    and did you ever think how the computer/calculator doing the calculation?


    ok, now i'll give little explanation for both question above. and dont worry,
    i wont go deeply into the processor architecture, just simple things that
    we have to understand to be a reverser or at least, an asm coder.

    every processors ever built, they all have REGISTERs to do arithmethic or
    bitwise operation (AND, OR, XOR, etc).
    for our lovely intel x86 (pentium 4 probably 786 :P), its has several register
    to do its operation. these registers will hold any number value according to
    its architecture whether 8 bits, 16 bits, or 32 bits.
    as we all have known before, intel x86 is a 32 bits processor, its registers will
    hold any value from 0 -> 0xFFFFFFFF

    80x86 processor has 8 general purpose registers, and these register
    mostly used while doing the reversing task.
    they are EAX, EBX, ECX, EDX, ESI, EDI, EBP, and ESP.
    Thus,

    Accumulator [E]AX (AH/AL) Multiply, divide, I/O, fast arithmetic.
    Base [E]BX (BH/BL) Pointer to base address (data segment).
    Count [E]CX (CH/CL) Count for loops, repeats, and shifts.
    Data [E]DX (DH/DL) Multiply, divide, and I/O.

    Source Index [E]SI Source string and index pointer.
    Destination Index [E]DI Destination string and index pointer.
    Base Pointer [E]BP Pointer to stack base address.
    Stack Pointer [E]SP Pointer to top of stack.

    where [E] mean extended for 32-bit register. Read below carefully.

    EAX is a 32bits register (a 'dword' can hold value up to 0xFFFFFFFF)
    The lower part of EAX is AX, a 16 bits register
    (16 bit register is inherited from 80286, an old 16 bit processor architecture)

    AX can be decomposed in his higher and lower part, AH and AL. (that are 8 bits register)

    here is the example:
    if the value of EAX == 0xCF3922DB2
    so AX == 0x2DB2 , AH == 0x2D, and AL == 0xB2.

    but there is something weird with higher part of EAX, 0xCF39, it cant be access
    directly. no worry, u will learn how to access it soon, after discovering bitwise
    manipulation techniques.

    * - the example above also could be apply to EBX, ECX and EDX registers
    ** - the value in eax is dependant for each others, if you modified AX to
    0x4F2A so, the new value of EAX == 0xCF3924F2A and vice versa.

    The other registers are:

    Flags [E]<Flags> Processor flags.
    Instruction Pointer [E]IP Memory location of current instruction.

    Code Segment CS Segment containing program code.
    Data Segment DS Segment containing program data.
    Stack Segment SS Segment for stack operations.
    Extra Segment ES Extra program data segment.
    Extra Segment FS Extra program data segment (386+).
    Extra Segment GS Extra program data segment (386+).

    Control Registers CR(0-3) Paging, caching, and protection (386+).
    Debug Registers DR(0-7) Data and instruction breakpoints (386+).
    Test Registers TR(3-7) Testing the TLB and cache (386+).

    Global Descriptor GDTR Address and limit of GDT (286+).
    Local Descriptor LDTR Address, limit, and selector of LDT (286+).
    Interrupt Descriptor IDTR Address and limit of IDT (286+).
    Task Register TR Address, limit, selector, and attributes of
    current task.

    btw, not all of registers above are useful for us a cracker/reverser.
    the register that should be care are the flags, EIP, DS, and SS for
    pointers thing.

    ok newbie reversers, the actual asm short class just started.


    Basic ASM opcodes (command).

    Before i start to explain these, find by yourself a disassembler like
    w32dasm or built-in disassembler in ollydbg. but, i recommend ollydbg..
    so, you can feel the code that i'll explain after this.

    A. MOV - move instruction
    --------

    This command prolly most used in a computer program. It simply can move
    a value, to a register. since MOV command didnt wipe the source, we
    should call it copy tho ;P.

    MOV destination, source

    btw, the destination could be any register or memory address.
    but the source could be immediate value, register, or memory address.
    NOTE: the memory address value is stored in a register.

    example 1:

    before: EAX == 0x000FFF0F, ECX == 0x00000000

    MOV EAX, 0x00965695
    MOV ECX, EAX

    after: EAX == 0x00965695, ECX == 0x00965695

    explanation:
    firstly, an immediate value = 0x965695 being moved to EAX
    after that, the value in EAX will be passed to ECX
    thats why, both register are same. its easy to understand,
    isnt it?



    example 2:

    Before:
    EAX == 0x0000000, ECX == 0x000011A0, EBP == 0x0012FCDC
    value in memory for SS:[EBP] == 0x00FF00FF

    MOV EAX,DWORD PTR SS:[EBP]
    MOV DWORD PTR SS:[EBP], ECX

    explanation:
    hmmm... this kind of operation need a proper explanation since it is
    very² important. while processing data, a cpu (processor) must have
    a memory module to save any value. btw, memory space has it own size and
    memory space also must be indexed to keep a lot of different values/datas
    by addressing. in win32 platform, it has 32 bit of virtual memory adress.
    so, the address or after this we'll call offset could be 0x0 to 0xFFFFFFFF
    (4294967295).

    MOV EAX,DWORD PTR SS:[EBP]
    now EBP == 0x0012FCDC, with this command, we will look 0x0012FCDC as memory
    offset. thus, the value of the offset is 0x00FF00FF. so, the value will be moved
    to EAX is 0x00FF00FF not 0012FCDC since it just a memory address or pointer to
    the value. btw, DWORD mean the value in offset 0x0012FCDC is in DWORD (32 bit).
    and DWORD also could be other like BYTE, or WORD.

    MOV DWORD PTR SS:[EBP], ECX
    this command is the reverse of command above. the value of ECX (0x000011A0) will
    be moved to offset 0x0012FCDC. thus, SS:[EBP] == 0x000011A0.

    After:
    EAX == 0x00FF00FF, ECX == 0x000011A0, EBP == 0x0012FCDC
    value in memory for SS:[EBP] == 0x000011A0

    note: in softice or ollydbg(with commandbar plugin), u can simply
    run 'd ebp' to check the value of for the address. d = dump.
    if the command like this
    MOV EAX,DWORD PTR SS:[EBP+8]
    simply type 'd ebp+8'



    B. CMP, JMP, JNZ, JE,... - compare and jump
    --------

    If you familiar with any high level programming language like c, basic, pascal
    you must already familiar with these statement

    if (a == b)
    do_this
    ...
    ...
    else
    do_that
    ...
    ...


    could you imagine how the cpu will do the comparison process? simply, it's just
    a dirty trick.

    * a - b = result. if the result = 0, aren't values the same?

    in asm, and of course while doing reversing, it look like these...

    -------------------------
    CMP EAX, ECX
    JE good_boy

    bad_boy
    ..
    ..

    good_boy:
    ..
    ..


    ------------------------

    JE is 'jump if equal' sometimes people use JZ (jump if zero), both are same
    zero mean equal.. read above *
    otherwise, JNZ mean jump if not zero or not equal..
    btw, after instruction CMP, theres a lot of jump commands like JGE
    (jump if greater or equal), JA (jump if above), JB (jump if below), etc.
    Every jump that is combined with a cmp, is a condicional jump. The only
    one jump that is not condicional, is the jmp command, which happens
    independently of any value or result.



    Conclusion.

    in this text, i wont explain much about about assembly programming, because
    mostly basic book of assembly have about 500 pages or 1000 and even more..
    its very long reading/learning. you have to find a book.
    if you want to know more deeply of intel 80x86 architecture, i suggest you read
    a book, 'The Art of Assembly Language" (AoA) by Randall Hyde. The useful chapters
    are :-
    Volume One: Chapter 2.5 and 2.6, Chapter 3 and Chapter 4
    Volume Two: All Chapters.

    After that, Iczelion win32asm tutorials will turn you as win32asm coders.
    In case you want to read it :P.
    More intresting, in very sooner, AMD will distribute AMD64. i hope its not hard
    for us, the reversers/asm coders to migrate on the new platform ;-).


    3. The Reversing.

    - Win32 API -

    In these days, most popular and most used operating system is micro$oft windows
    platform including win98, win2k, and lately winxp. all of those os's are typically
    same for their programming interface, they all use win32 API (Application programming
    interface). in the old DOS days, assembly programmer used to interact directly to
    computer interrupt to communicate with computer system hardware. But, after win32 API
    was introduced, application programmers no longer have to know much about the hardware,
    they just have to know API collection to be used their program. as example, to display
    a warning messagebox, theres an API for the purpose, which will be called.
    in c programming language, the API function could be called like this.

    MessageBox(hwnd, "Your input is wrong!", "Warning!", MB_OK);

    as defined in Win32 API documentation.

    int MessageBox(

    HWND hWnd, // handle of owner window
    LPCTSTR lpText, // address of text in message box
    LPCTSTR lpCaption, // address of title of message box
    UINT uType // style of message box
    );

    the MessageBox function was included in USER32.dll and could be imported by any
    win32 applications. beside that function, there are thousands of win32 API
    functions collection which implemented in kernel32.dll, GDI32.dll, etc.

    DLL (Dynamic Linked Library)
    the .dll files is a collection of ready made function which could be use by
    programmers. in c, if we made a function for any routine, we can call it
    many times so the functions in .dll files. the different is, the function in
    c will be included in the .exe itself but not the fuctions in .dll, they in
    other file and will be opened after being called. Thats why they called as
    Dynamic Linked Library.

    i think overview above about win32 api is enough. we will discuss more about
    how to manipulate win32 api in reversing later.



    - PE Files Format -

    if you're from *nix/linux world, elf format for the executable files maybe
    familiar to you. but we are in windows now, and it uses PE format.
    i will not teach you about it. Just want to give simple explanation of it.
    there are many good tutorials about PE by Matt Pietrek, Mammon, LUEVELSMEYER,
    etc.

    for windows, all executable file names' are in *.exe form. the code in the files
    are segmented. if you had read assembly in DOS book, the *.exe also must be
    segmented unless it is *.com. the segmentations must be done because of the
    computer architecture (x86). segments in easy word is 'memory block'.

    in windows, the segmentations are slightly different from dos.
    because windows has memory management system all application level programs
    will be loaded into their very own virtual memory locations. to make it simple,
    the PE files (executables, .DLL, .OCX, .SYS, .CPL and .SCR files) structure
    stored on disk is the same after windows load it into memory.

    to get the big picture, get yourself a Hex Editor (i prefer Hex Workshop) and
    OllyDbg. Open any PE files (*.exe) in both tools.

    in ollyDbg, press Alt-M for memory map.
    Look at address 0x00400000. OllyDbg will tell us it is address for PE Headers.
    the segment size for PE Headers usually 0x1000 bytes or 4096 bytes.
    after that, at 0x00401000 is code segment. the size of code segment depends
    on the program.
    later on, there are several segmentation for imports/exports, data, and resources.
    if you're lucky, you'll find strange segments especially if it is
    packed/protected. For example: zip self-extract or upx packed files. In windows,
    segments are called as sections.

    After that, in the hex editor. please check by yourself whether the first 4096 bytes
    are PE Headers section. btw, 4096 bytes are too big for PE Headers data, thats why
    you'll find many 0x0 value bytes.

    for more, please try to open other executables files using OllyDbg. But dont be surprised,
    all PE Files stored in virtual memory at 0x00400000 base address.
    This is applied to all executables.

    in hex editor, you will not find 0x400000. The files begin at address (or could call it offset)
    0x0. for the sake of the windows memory management, unfortunately we must learn about
    Relative Virtual Address(RVA). fortunately it very easy to understand.

    for the example, we want to make a patch at offset 0x401290. as we knew before,
    the offset dont exist in hex editor.

    so lets do simple maths.

    (Virtual address 0x401290)-(base address 0x400000) = RVA 0x1290

    to make the patch, we can go to offset 0x1290 in hex editor.

    please take note, above example to find physical offset
    on disk true if only the size of PE Headers is 0x1000 bytes.
    sometimes, optimized executables just took 0x400 bytes for PE Headers on disk.
    thus the virtual size in virtual memory still 0x1000.
    u can check size of headers using pe editor like procdump, lordPE, etc. Also
    OllyDebugger can show you this information.

    using pe editor, you find, let say, pe header's size is 0x400. so code section
    starts at physical address (raw) 0x400 / virtual address at 0x1000.
    lets do the maths again.

    0x1000 - 0x400 = 0xC00

    base address still 0x400000.
    and the virtual offset that we want to patch is 0x404320.

    to convert 0x404320 to disk raw offset,

    0x4320 - 0xC00 = 0x3720

    ok.. thats enough...non standard size of PE Headers make little mess.. just because
    0x1000 - 0x_____ != 0.


    The reversing itself.
    ---------------------

    For us newbie reversers, the most intresting things to be reversed are protected
    sharewares. But, for advanced reverser, there are a lot more advanced things like
    packing/protecting and unpacking/unprotecting of PE files(win32 .exe files), adding
    and modifying function in an application, stealing codes, reversing tools coding,
    etc.

    Since the most target for newbie cracker/reverser are sharewares protected by
    nag screen, or serial numbers, get rid off the protection then getting registrated
    version of the shareware is a great victory for newbies.

    before that, all cracker/reverser must use at least a tool to attack the targets.
    the must used tool is called debugger. general purpose of any debugger is to pause
    or break the processor of any sequence of executions. the problem here is, the
    program code is too long, very long enough. its hard to find the exact location
    where to break when program being executed. so we need a good disassembler to help
    us to find them. an average disassembler i.e W32dasm is good enough for use newbie.
    but theres also excellant disassembler called IDA.
    btw, in win32 reversing, we're too lucky because we can manipulate win32 api calls
    as a breakpoint.

    for the example..
    when a shareware request input from a user for a name and serial number, it will
    calculate it to make sure the serial is correct and turn on the registered version
    of the shareware. otherwise, it will display a message (commonly it's a messagebox
    or a dialogbox) to tell us the serial we've entered is wrong. from here, we can use
    messagebox or dialogbox API function as breakpoints to know from which location
    the messagebox was called.



    The Cracking Tools.
    -------------------

    You'll find so many cracking tools coded by crackers/coders/reversers out there
    from around the world. But we'll use just a few of them especially in the beginning.
    The very basic tools are a debugger and a disassembler. And if necesarry, an unpacker
    for packed/protected programs.


    1. Debugger

    First at all, you have to know there are two kind of debugger, ring-0 level
    (system level) and ring-3 level (application level). But now, we wont touch the
    low level as we dont need them currently.
    Although many ring-0/ring-3 debugger on the black market(you know what i mean), i just
    recommended OllyDbg because its very simple, easy to use, yet also powerful.
    I think i dont have to teach you to use it because you can learn it by yourself in
    minutes. By the way, u can read several tutes about ollydbg from my website by
    googling for "zephyrous ollydbg tutorial" or any tutes by other writers.
    Biw-reversing site has very good tutorials collection.


    2. Disassembler

    The most popular are w32dasm and IDA(for advanced reverser). The usage for
    w32dasm is pretty straight forward and we can use it for dead listing analysis.
    All debugger is a disassembler actually, but they have different function.
    It's depend on you the way of your codes analysis job.
    After you're becoming better in reversing, you'll find IDA so powerful and very
    useful in specific tasks.

    3. Unpacker

    Generally speaking, all protection(nag screen, serial) are easy to be removed
    unless the code itself has been scrambled into wild binary code and cannot be blindly
    patched. When the program will be executed, the internal descrambled engine will extract
    true binary code for the program to run well. So, the unpacker's job is to extract the
    right codes for patching and analysis.


    How to Crack?
    -------------

    This question is too general because there are too many techniques can be used.
    Its depend on us cracker to find the best method for every different problems. The most
    used technique is by 'guessing', but we won't do it blindly (smart guessing) just like in
    any puzzle games. We have to guess because we dont know where is the protection. So, we
    have to learn about win32 API as had been discussed before.

    For the example (again), a shareware is asking for a serial number. To received the serial
    numbers from user, the program will provided an 'Edit Box'. After user has input the some
    text in edit box, the program will copy the text to the computer memory for calculation whether
    the serial is true or false. Then, some programs will warn if the serial is wrong with
    a 'Dialog Box' or 'Message Box'.

    The highlighted text (Edit Box,Dialog Box, Message Box) are parts of Win32 API. To read text
    from Edit Box, programmer will call GetDlgItemTextA or GetWindowTextA. However, to display a
    dialog box or message box, DialogBoxParamA or MessageBoxA will be called. From here, we will
    use these API as breakpoints in debugger, so the debugger will pause the program execution
    when the breakpoints have been called. After that, we can continue the program execution
    line by line using F8 key(in ollydbg) for live tracing. If we're lucky, the codes for serial
    calculations will be found after pressing F8 several times. But most times, its not easy
    to find the exact location for serial calculations.


    The way computer stored data especially name in memory.
    For serial calculations, some algos will compute the serial from the user's name.

    Example:

    "The Reverser"
    in memory its become
    54 68 65 20 52 65 76 65 72 73 65 72 (in hexadecimal)
    where T = 0x54, h = 0x58, e = 0x65, ..., r = 0x72

    Computer naturally just could store numbers. So it used number from 0 - 255 or
    0x0 - 0xFF to represent any characters and called ASCII codes. An ASCII character
    takes a byte. The homework, get yourselves an ASCII codes table for full reference.

    Quick reference :-

    0-9 => 0x30 - 0x39
    A-Z => 0x41 - 0x5A
    a-z => 0x61 - 0x7A

    To calculate serial, these ASCII values usually will be used. But each character in bytes.
    So, sometimes it more efficient to use lower part of the registers, i.e AL, AH, CL, CH.
    As usual, maths operation will be used thoroughly like add, substract, multiply, division,
    modulus, etc including bitwise in the algorithms.

    I think it is enough for now. I wont go further because there are a lot of tutorials
    about cracking for specific targets and/or using specific techniques.
    a good start is finding the collection for the tutorials at krobar's collection site,
    biw-reversing, anticrack.de, and google at it best. maybe i'll make another tutorial
    based on this little guide but not in general. i will go specifically like patching,
    serial fishing, keygenning, unpacking, etc.

    Happy Reversing and Have Fun!

  9. #159
    پروفشنال Morteza_SOS's Avatar
    تاريخ عضويت
    Apr 2006
    پست ها
    577

    پيش فرض

    Manually unpacking this packer with OllyDbg, and IAT reconstruction with ImpRec.
    This one has some catchy anti-debugging tricks aboard

    Hallo to all my readerz.Well,since I have see no unpack tutorial in this
    protector I decided to make one.The zip containz the packed and the unpacked
    files.This is not a hard protector at all,and I don't know why no tutor
    exists till now.Let us begin...

    Toolz used: Olly v1.10,OllyDump Plugin,HideOlly plugin,ImpRec v1.6f

    Ok,I used the Hide Plug to hide Olly from the IsDebuggerPresent API that
    is used as an anti-debugging "trick".So,use this plug to avoid setting
    breakpoints on that API constantly.

    Open the target exe and load it into Olly.If any messages appear press OK
    and Yes.Those messages inform U that Olly has quessed that maybe the target
    is packed,and asks for the continuation of the analyzation.So U are at EP (Entry Point)
    HeRe:


    0050F000 > $ 60 PUSHAD
    0050F001 . F8 CLC
    0050F002 . F8 CLC
    0050F003 . 4F DEC EDI
    0050F004 . 87CF XCHG EDI,ECX
    0050F006 . 66:B9 7F55 MOV CX,557F
    0050F00A . 7E 03 JLE SHORT ColorPic.0050F00F
    0050F00C . 7F 01 JG SHORT ColorPic.0050F00F
    0050F00E . 7B 75 JPO SHORT ColorPic.0050F085
    0050F010 01 DB 01
    0050F011 F9 DB F9
    0050F012 7C DB 7C ; CHAR '|'
    0050F013 03 DB 03


    Now make sure that U don't have any hardware,memory,software or other breakpoints set
    because this packer will find them and will stop the execution of the program,if U
    start to executing it.Make also sure that the only exceptions that are checked in
    Debbuging Options are Ignore memory access violations in kernel32 and int3 breaks.Well I
    figured out this combination of checked exception during trying to unpack it,do not brake your
    mind with that.Now,press Shift+F9,an exception occured,continue with Shift+F9.Shit!
    The application terminates,and killz Olly also.Well this is an anti-debbuging trick
    that Uses three API's:With createtoolhelp32snapshot,creates a list with the current
    handles of the running processes.With Process32first it takes the first handle and
    takes the rest using process32next.After taking all those handles,the prog has
    hardcoded (well actually created during runtime) some names of debuggerz and unprotectorz,
    including Olly'z name (OLLYDBG.exe).It searches again using those API's for a proccess
    named OLLYDBG (and others),and compares it's handler with it's running father thread.If it is the
    same,it terminates and terminates Olly.If one of the running processes is also a
    "bad" program,it may terminate it.So what we will do?

    We will change the code of createtoolhelp32snapshot API,to return
    immediatelly using a ret opcode.Have also in mind that we cannot place any breakpoints
    at the first opcode of any API (meaning that U cannot double-click on API's name in
    search name in all modules and place a breakpoint at the first opcode,but also do
    not put an opcode using commandline plugin like:bp createtoolhelp32snapshot).This is because
    the protector,just before calling an API searches for the first opcode.If there finds a CC
    instruction (which is a software breakpoint that is set using eg "bp createtoolhelp32snapshot")
    it termimanes.For this,it just uses such kind of commands:


    MOV eax,byte ptr ds:[XXXXXXXX] <--- XXXXXXXX location contains the address of an API
    CMP eax,CC
    JNZ YYYYYYYY


    So,load again the target.Do not run yet.In code section,right click and search for name in all
    modules.Find createtoolhelp32snapshot API,and double click on it.U are at it's code,HeRe:


    77E92ED1 > 55 PUSH EBP
    77E92ED2 8BEC MOV EBP,ESP
    77E92ED4 83EC 0C SUB ESP,0C
    77E92ED7 56 PUSH ESI
    77E92ED8 8B75 0C MOV ESI,DWORD PTR SS:[EBP+C]
    77E92EDB 85F6 TEST ESI,ESI
    77E92EDD 0F84 3FE60000 JE kernel32.77EA1522
    77E92EE3 8D45 FC LEA EAX,DWORD PTR SS:[EBP-4]



    See a little down,till the retn where the code of the API ends.This is HeRe:



    77E92F2A 56 PUSH ESI
    77E92F2B FF75 08 PUSH DWORD PTR SS:[EBP+8]
    77E92F2E E8 12000000 CALL kernel32.77E92F45
    77E92F33 8BF0 MOV ESI,EAX
    77E92F35 85F6 TEST ESI,ESI
    77E92F37 0F8C F4E50000 JL kernel32.77EA1531
    77E92F3D 8B45 0C MOV EAX,DWORD PTR SS:[EBP+C]
    77E92F40 5E POP ESI
    77E92F41 C9 LEAVE
    77E92F42 C2 0800 RETN 8


    Ok,it ends with a RETN 8.So,go at 77E92ED2 and enter the following new commands:


    77E92ED1 > 55 PUSH EBP
    77E92ED2 5D POP EBP
    77E92ED3 33C0 XOR EAX,EAX
    77E92ED5 C2 0800 RETN 8


    The POP instruction is to make stack as it was before the PUSH EBP,the XOR makes EAX=0
    and is used as a flag from the program to continue the execution without crashing (because
    it will think that there are not any other processes running at that time,nothing bad actually)
    and the retn 8 to return to the code.So,now no proccesses taken,no Olly detection.

    Press Shift+F9 (if exceptions occur,again Shift+F9) and the prog runz just fine under Olly.
    Now reload it into Olly,make all the anti-tracing things we said and press one time Shift+F9.
    Olly breaks for an exception of access violation.Now press the "M" button and see the contents
    of memory.Right click on code section (named .text) and set a memory breakpoint on access.Now
    one more time Shift+F9,Olly pauses and U see garbage.Right click->Analysis->Analyze code and
    we are actually at the OEP,HeRe:



    0041A4C9 . 68 28F34300 PUSH ColorPic.0043F328
    0041A4CE . 68 58DC4100 PUSH ColorPic.0041DC58 ; SE handler installation
    0041A4D3 . 64:A1 00000000 MOV EAX,DWORD PTR FS:[0]
    0041A4D9 . 50 PUSH EAX
    0041A4DA . 64:8925 000000>MOV DWORD PTR FS:[0],ESP
    0041A4E1 . 83EC 58 SUB ESP,58
    0041A4E4 . 53 PUSH EBX
    0041A4E5 . 56 PUSH ESI
    0041A4E6 . 57 PUSH EDI
    0041A4E7 . 8965 E8 MOV DWORD PTR SS:[EBP-18],ESP
    0041A4EA . FF15 50B24300 CALL DWORD PTR DS:[43B250] ; kernel32.GetVersion



    Remove memory breakpoint now and dump the exe using Olly plugin,without having checked
    the Import rebuilding option.Do not close Olly.Now open ImpRec and enter as OEP the
    value (OEP as appearz)-(ImageBase)=0041A4C9-00400000=1A4C9.Now IAT autosearch and Get
    Imports.Now show invalid.We have one invalid thunk.Try tracing levelz,no one validates the
    thunk.Well,most of the tutorz out there would now just say "now cut the invalid thunks etc".
    But if U cut the thunk as invalid,the exe will not work.Why?Because this pointer that is
    unresovled (in me is 5124DB) and should properely have pointed at an API,is just showing
    to a memory address that code of the exe is.This code of the exe has been dumped with
    OllyDump,and may was part of the protector,but now is part of the exe.And cutting this
    thunk we prevent this necessary code to be executed,althought it has nothing to do with
    APIs.And where is the API that should have been pointed here,properely?Well,as there is
    no other invalid thunk,may be one of the valids and has been just replaced (moved) in
    another place (another pointer).Anyway,now fix dump and it will tell U that there are still
    unresolved pointers.Well,not really.Run the fixed exe and...yeap,it's unpacked!

  10. #160
    پروفشنال Morteza_SOS's Avatar
    تاريخ عضويت
    Apr 2006
    پست ها
    577

    پيش فرض

    به نام خدا
    سلام فعلا یه چند روزی باید استراحت کنم خیلی خسته ام .... ولی دوباره بر می گردم با دستی پر از آموزش !
    از دوستان می خوام اگر می تونند به من کمک کنند و آموزش های این تاپیک را پی دی اف کنند .
    اگر هم کسی آموزشی ، سایتی و .... چیزی داشت برام Pm بزنه خوشحال می شم .

    تا بعد خدانگهدار عزیزم .

Thread Information

Users Browsing this Thread

هم اکنون 1 کاربر در حال مشاهده این تاپیک میباشد. (0 کاربر عضو شده و 1 مهمان)

User Tag List

قوانين ايجاد تاپيک در انجمن

  • شما نمی توانید تاپیک ایحاد کنید
  • شما نمی توانید پاسخی ارسال کنید
  • شما نمی توانید فایل پیوست کنید
  • شما نمی توانید پاسخ خود را ویرایش کنید
  •