Jump to content

M2G

Moderators
  • Posts

    1838
  • Joined

  • Last visited

  • Days Won

    32

Everything posted by M2G

  1. Many times I find myself having to write my own tool in order to exploit a Blind SQL Injection which public tools normally would not be able to exploit. It may be because it is behind a WAF/IDS, or for a SQL challenge, or because it is Base64 encoded or some other peculiar situation where normal SQLi attack tools just will not work. What I will demonstrate in this post is a way of taking a shortcut and avoiding having to create your own program by using Burp Suite which will hopefully save you valuable time. I highly recommend Burp for anyone that is serious about pen-testing. The Pro version is very affordable and has a great ton a features which makes auditing a breeze (the easter egg is hilarious too). Once a target has been set in the scope and a SQL Injection has been located, we send the URL to Burp's Intruder. Next step is to define the SQL Injection and the position where the character to be brute-forced will be. For this example, I will be extracting the database(). After setting the position, we need to define the payload. We select numbers as our payload and define a range from 32 to 126. If you look at the Ascii table, this range accounts for all the characters that we need. [img[http://www.websec.ca/img/burp-sqli/define_payload.png The last step before launching the attack is to set a string to be matched when the query returns true, just like you would with any other SQLi tool. In this case, the string to be matched will be 'lightos'. Now we can go to the menu under Intruder and select Start Attack. This will open a window that will display the results from each request. When the string is matched, it will clearly be displayed and that will indicate which is the correct character. he string was successfully matched on number 84, which is the decimal representation of the letter T. This is the first letter of database(), which value is Test. I have included the following video to better demonstrate the process: Burp Suite Sursa
  2. Amaratul ala de jar e o librarie pe care o poti folosii in proiectul tau pentru a apela diverse metode din clase deja scrise. Trebuie sa setezi acel jar in proiectul tau ca sa poata sa iti vada acele clase inpachetate acolo. Nu am prea lucrat cu android. Foloseste Eclipse ca si IDE si iti zice el ce posibilitati ai de importuri (use ctrl+space). Nu prea inteleg ce vrei sa faci si de ce nu iti merge, ce exceptii iti arunca? Un printscreen cu stack-ul ar ajuta foarte mult. Da mai mult detalii, pune println-uri. Pune breackpointuri si intra in debug mode sa vezi unde ajung mesajele si ce ajunge. Cauta pe google si incearca sa intelegi logica programului in cazul in care ai gasit acolo exemple pe care doar le rulezi. Da-mi in pm un exemplu de cod daca nu reusesti si incerc sa te ajut.
  3. Posteaza articole care tin de domeniul forumului daca vrei sa mai ramai pe aici. https://rstcenter.com/forum/55163-warnuri-si-banuri-pentru-offtopic.rst
  4. Nu am nimic cu tine dar hai sa nu mai fim hateri si sa ne uitam putin si in oala noastra.
  5. M2G

    PLC Programming

    Ti-am zis prostii, lasa. Scuze, credeam ca e vorba despre microcontrollere.
  6. M2G

    PLC Programming

    Ce mictrocontroller folosesti si ce limbaj vrei pentru el? ASM sau C? De obicei e suficient datasheet-ul mictrocontrollerului, acolo iti scrie toti registrii si cum sa ii setezi.
  7. Le urc si acolo acum. Doar ca acolo apar mai greu ca dureaza pana le muta tex dintr-o parte in alta. Revin aici cu edit la link-ul de pe docs.rtfm cand or sa fie disponibile acolo.
  8. Am vazut pe aici ca multa lume ar vrea sa invete andoid. Content: Download: [RST] Carti Android - Ge.tt Adresa de pe Docs.rtfm.us: http://docs.rtfm.us/Users/M2G/Android/Android%20eBooks/
  9. Inca merge. Toata chestia e ca sa oprit developementul. Nu o sa il mai imbunatateasca si nu or sa mai apara versiuni noi. Cele vechi or sa mearga, nu au legatura cu faptul ca a renuntat la proiect.
  10. Nu cred ca e chiar asa. Toate acele optiuni erau clar optiunile unui troian. Aveai filemager, suport pentru decriptarea parolelor salvate in browsere(stealer), functii prin care puteai ascunde taskbar-ul sau chestii degenul acesta. Optiuni care sunt clare dezvoltate avand in minte un troian. Daca nu ma insel avea un buton prin meniu care trimitea pe site-ul lui BUNNN pentru a cumpara father crypter. Ca folosea ca si "cover" povestea cu protejarea calculatorului, supravegherea copiilor e altceva. Cred ca a dat de probleme cu autoritatile si acum a zis povestea asta ca sa se scoata cu fata curata. Probabil oricine ar fi facut la fel daca ar fi fost in locul lui. Depinde cum privesti lucrurile...
  11. It is with deep regret that i am here to announce the end of project DarkComet RAT after over 4 years of developement, hardwork day and night to offer you for free a tool with the will to meet community's expectations for a program of type Remote Administration Tool. I have devoted years with a nonprofit philosophy for you to enjoy without asking anything in return other than respect of the rules, unfortunately some of you couldn't respect the terms so because of you (generally speaking) made the DarkComet RAT geo cruiser end. i still wish to point out that i will remain on the scene of Computer Security and will keep developing freeware softwares but this time without having me taking risks because none of the futur ones will be close to be a Malware. This obviously means the deletion of the following softwares: (Celesty binder, Comet Beam, VertexNET Loader and the project FrozenTime RAT who was under developement for you .. unwisely.) But all the knowledge i acquired developing my computer security projects isn't lost considering i will only be doing softwares that require confirmations etc to install themselves and remain visible (impossible to cheat this time) Unlike what a handfull of people think i never cautioned small/huge hacker groups who used my software wrongly, my goals always where to provide acces to tools more powerfull than any paying/private existing tool in terms of security and all for free ! (for familys who wished to keep there eye on their kids or regular folks looking into acquiring some experience with such tools, users who wished to keep track on their machine any place in the world etc.) Why did i take such a decision ? Like it was said above because of the missuse of the tool, and unlike so many of you seem to believe i can be held responsible of your actions, and if there is something i will not tolerate is to have to pay the consequences for your mistakes and i will not cover for you. The law is how it is and i must abide by the rules, yes its unfortunate for devs in security but thats how it is. Without mentioning what happenened in Syria... Finally i wish to thank all those who supported me over the years aswell as all those who followed the rules: Damien Bancal (http://zataz.com), Mohit Kumar (http://TheHackerNews.com), $Instincts$, Nacra, DALLOZ, Kevin Mitnick (http://mitnicksecurity.com), Read101 (Former leader of the crew Are you Fearless) and all those i couldn't list publicly because the list would be way too long.. DarkComet RAT ends like this after several years of res/dev and with thousands of users through the world, hundreds of codes lines and over ten versions if you include (synRAT), the source codes will remain private and not for sale. This was a very hard decision to take, probably the hardest i ever had because after so many years its more than just a project, its a piece of you. ~DarkcoderSc (Jean-Pierre LESUEUR) Link: DarkComet RAT - Official
  12. Daca vine garda, fugi.
  13. Security Researchers from S21sec, has spotted two major changes in the latest version of Citadel Trojan. The two major changes 'Anti-emulator' and 'Encryption change' try to make malware analysts' life harder. The anti-emulator: When it starts, a built-in detective checks if it is running in a virtual machine or in sandboxed environment (CWSandbox, VMware, Virtualbox). If it detects their presence, it starts to behave differently. Details were not disclosed, and the technology is very tricky. According to researchers, It simply scans through the resources of the currently running processes and looks for specific patterns for instance inside the "CompanyName" field, such as 'vmware','sandbox','virtualbox','geswall'. While running in the VM, The Trojan creates a fake domain name and attempts to connect to it. This strategy should fool the researchers into believing that the (C&C) command and control server cannot be reached and that the bot is dead. This is not the only change brought to Citadel. Experts have found that the RC4 is slightly different compared to previous versions, an internal hash being added to the algorithm. Sursa
  14. A password is the only thing that protects secure information on a network system. If we want to access secure information, we must be an authorize members of the system or network. According numerous security studies, passwords are the biggest security hole in any network. If any unauthorized individual manages to get the right password, he will be able to access secure data on the system. Although many systems try to improve security using various methods there are some tools which are far more effective at hacking into a network system than others. THC Hydra is one of the primary tools that can show how easy it is to gain unauthorized access to a network system from remote location. THC Hydra is not the only tool that can crack FTP or Telnet passwords from a remote computer. Indeed, there are various tools available that can both do the job and also support various protocols while using a parallel connection to crack a network. But THC Hydra is considered the best weapon for hacking a network, as it is known for its speed and efficiency. The THC Hydra performs a brute-force attack based on a password dictionary. Brute-force Attack: Brute-force attack is the most widely used attack for password cracking. This attack uses all possible permutations of a password until the correct password is found. For example: If the password is 3 characters long and consists of both letters and numbers. Then a brute-force attack will use 2,38,328 different password as your password. For First character: total lower case letters (26) + total upper case letters (26) + total numbers (10) = 62 For Second character: same = 62 For Third character: same = 62 Total permutations = 62*62*62 = 2,38,328 About THC Hydra: Before learning about password cracking with this tool, you must know few things about the method itself. THC Hydra is the fast network logon cracker. It connects with multiple parallel connections from the remote system and then starts its attack. It is able to crack passwords used by all kinds of services. Compared with other available logon password crackers, this tool supports more services and protocols and is faster than others. List of Protocols THC Hydra supports: These are the protocols that this tool supports, and we can crack the password of all these services using this logon method: AFP, Cisco AAA, Cisco auth, Cisco enable, CVS, Firebird, FTP, HTTP-FORM-GET, HTTP-FORM-POST, HTTP-GET, HTTP-HEAD, HTTP-PROXY, HTTPS-FORM-GET, HTTPS-FORM-POST, HTTPS-GET, HTTPS-HEAD, HTTP-Proxy, ICQ, IMAP, IRC, LDAP, MS-SQL, MYSQL, NCP, NNTP, Oracle Listener, Oracle SID, Oracle, PC-Anywhere, PCNFS, POP3, POSTGRES, RDP, Rexec, Rlogin, Rsh, SAP/R3, SIP, SMB, SMTP, SMTP Enum, SNMP, SOCKS5, SSH (v1 and v2), Subversion, Teamspeak (TS2), Telnet, VMware-Auth, VNC and XMPP. Supported Platforms: This network logon cracker is available for most of the available platforms including those listed below: All UNIX platforms (Linux, Solaris, etc.) Mac OS/X Windows with Cygwin (both ipv4 and ipv6) Mobile systems based on Linux or Mac OS/X (e.g. Android, iPhone, Zaurus, iPaq) Hydra Explained and its Usage: For command line usage, we will use following command: Here a different argument has a different meaning. Read the meaning of these commands in the line arguments below: How to crack Telnet password with THC Hydra: First of all, download Hydra from the official website. If you are using the Windows version, you will have to work on a console as there are no GUI for Windows users. I am demonstrating this tool on a Windows system below. Download the zip file and extract it on the system. Now follow these steps: Click on Start, type CMD in the search bar (in Windows 7), and open command prompt. Now change the command prompt location to the hydra folder by using CD command. Now we will execute the Hydra by typing hydra.exe in the command prompt Now we need to select the target computer. At this moment we can use Nmap for scanning IP and open ports. So download the Nmap in your system. Windows users should download the Windows version. After downloading Nmap, scan for IPs in range. Also check for open ports in these IP addresses. How to Use Nmap? The use of Nmap is really simple. If you do not know, I will be posting a more detailed article shortly, which will help you. Suppose I am in a network which has IP series of 192.168.0.x and I want to break into the Telnet of a system in this network. I will use Nmap to find my target system. First of all, we will scan to check which systems are alive on the network. Use Nmap to perform a simple ping and get the list of all systems alive on the network. Use this command: Now see the results of this ping scan. You will get the list of all IP addresses in the system which are alive. I will pick one from the list to target. I have chosen the system with IP address 192.168.0.7 Now we will check whether the Telnet port is open in the target computer or not. So use this command for simple port scan: This command will show you all the services currently running on the target computer. If the Telnet service is running on the target system, we are ready for the attack. If not, we will have to select another computer for the attack. After locating a suitable target, we will begin the attack using Hyrdra. There are two pieces of data we need to have on hand before we can begin the attack: the username list and a password list. The username list is being used in case we do not know the username. The password list will contain the list of passwords that will be used by Hydra for brute-forcing. Case 1: Suppose we know the username. Let us assume that the username for the target Telnet is admin. Now we will use the command to run the attack: Here in passlist.txt is the list of possible passwords. Hydra will use each password for the selected username and will try to login. If a password from the list is matched, it will stop the scanning and show the username and password combination for the target Telnet. If no password from the passlist.txt matches with the username, it will simply stop the scan. If you want to save the scan results into a file, you will have to change the command and add the name of the output file into command line argument. This command will save the result to the output file test.txt. Case 2: In case you do not know the username, you can use the guess list of usernames along with the password list. Now we will use the command to run the attack: In username.txt the system stores the guess list for possible usernames for the target admin. In addition, passlist.txt is the guess list for possible passwords. To save the result in an output file, we will use a similar command to the one I have already written. The only difference is that we will utilize the username list here: One thing to note is that using a username and password list changes one thing in the command that is not noticeable for all users. When I have executed the command for a single username, I used –l admin, but I use -L username.txt when I used a list. Here we can see the difference between –L and-l: When I use a single username, I use small caps for l, but when using the username list, I use a capital L. If you are on Ubuntu or any other Linux-based operating system, this tool will be easier to use. This tool comes with a nice GUI for Linux-based operating systems, so you will not need to learn Hydra commands. Working with this system requires using similar tools and commands are executed in the background of GUI. This was a short demonstration of cracking Telnet passwords using a Hydra network logon cracker. How to Crack FTP Password with THC Hydra: In the previous section I wrote about cracking Telnet passwords with Hydra. As I already mentioned, this method is a network logon cracker and it supports many network protocols. As a result, Hydra is used to crack most of network logins. Cracking FTP passwords essentially involves the same process as cracking Telnet passwords. You just need to find the target system with an open FTP port, and then use Hydra to crack the passwords with a password dictionary. If you are not sure about the username, you can use username dictionary along with the password dictionary. Now we will use the command to run the attack: You can see that the command is similar to the command used with Telnet cracking. Only here I have replaced the Telnet with “ftp” to tell Hydra that it has to attack the FTP port this time. You can change the target system’s IP accordingly. You can also use admin list as given below: All other things are almost exactly the same: You can use “ftp” to replace any other supported protocols. How to Protect Against a Hydra Attack: Protection against this kind of brute-force attack is divided into three parts: Always check your logs against suspicious activity. Log files will help you learn more about the attacker. Always use strong password that are adequate in length. Use both upper and lower cases, numbers, and special characters. Always restrict the number of invalid logins that can be attempted, and then block the login from that IP Conclusion: THC Hydra is really a nice and effective network logon cracker. Of all the available network login cracking tools, it is the most effective. It also uses dictionary-based attacks with multiple connections, which makes it faster than other tools. So always use the strongest passwords possible. If you use a strong password, which incorporates the use of capital and small letters, numbers, and special characters, then you increase security by increasing the number of permutations Hydra must extrapolate. You can also setup server restrictions in which you can disallow login after 3 invalid login attempts. This will block a brute-force attack Reference: https://www.owasp.org/index.php/Testing_for_Brute_Force_%28OWASP-AT-004%29 Thc-hydra - Aldeid http://www.thc.org/thc-hydra/README Sursa
  15. M2G

    Class hour

    Hai ca ma bag si eu. Ca elev la alte sectiuni si ca prof pe java daca sunt persoane interesate.
  16. M2G

    Class hour

    Dupa fiecare lectie sa se dea cateva teme, probleme de rezolvat si o saptamana la dispozitie. Cursantii care nu rezolva, ban 5 zile. La 3 banuri, exclusi din clasa respectiva. Daca nu isi asuma responsabilitatea aceasta inseamna ca nu vor sa invete si nu au ce cauta pe clasa respectiva.
  17. Nu sectiunile sunt problema. Ai ceva de zis despre domeniile de care vorbesti? Atunci posteaza.
  18. Consider ca programul nu se ridica asteptarilor mele, ca este deprecated, ca nu are un design destul de bun si ca se poate mai bine. Pana cand o sa am timp sa fac o alta versiune, proiectul acesta e abandonat complet. Intr-o versiune viitoare, daca o sa fie una, o sa fie totul rescris de la 0 intr-un stil mai profesionist. Closed!
  19. Sau mai simplu si fara alte third party. Control Panel\Network and Internet\Network Connections
  20. Inca nu e in stadiul final. Daca era, probabil era lansat deja. E normal sa apara erori pe asa aplicatii mari la care sa facut un redesign total atat in frontend cat si in backend. Nu am incercat noul sistem de operare, o sa il iau cand apare versinea finala dar toate persoanele cu care am discutat au avut cuvinte de lauda despre el.
  21. Pai eu daca fac un program prog1.1.exe si ti-l dau tie. Tu "nu prea poti sa il editezi". Eu am codul sursa si il modific cum vreau. Dupa modificari zic ca e prog1.2.exe si iti trimit iar programul gata compilat. Dupa ce ai scris un program nu trimiti sursa, trimiti doar fisierele binare care sunt gata compilate. Astfel tu ca si dezvoltator ai codul sursa si poti modifica ce vrei tu si cum vrei tu. Cei care au doar executabilul nu pot face asta decat prin reverse engineering.
  22. Suna fancy dar nu prea dau multe detalii despre cum e implementat, care e cheia criptarii(cheie care are doar numere sau are si alte caractere). Din cate am inteles din ce am citit acea cheie era formata doar din numere. Nu specifica nimic despre modul in care sa generat entropia. E interesant pentru cei care fac cercetare in domeniul acesta dar fiind vorba de un sistem criptografic care inca nu e standardizat era oarecum de asteptat sa se intample asta. Aceste cercetari au loc pentru a demonstra securitatea sau insecuritatea unui anumit standard(algoritm criptografic). Deocamdata sistemele criptografice bazate pe chei publice sunt inca sigure. Ramane de vazut ce o sa se intample odata cu dezvoltarea puterii de calcul. http://courses.csail.mit.edu/6.897/spring04/L25.pdf
  23. PDF: http://crypto.stanford.edu/cs155old/cs155-spring10/papers/web-session-management.pdf
  24. PDF: http://seclab.stanford.edu/websec/chromium/chromium-security-architecture.pdf Despre sandbox: Sandbox - The Chromium Projects
  25. --[ 1.0 Introduction In this paper I'm going to describe two classes of programming bugs which can sometimes allow a malicious user to modify the execution path of an affected process. Both of these classes of bug work by causing variables to contain unexpected values, and so are not as "direct" as classes which overwrite memory, e.g. buffer overflows or format strings. All the examples given in the paper are in C, so a basic familiarity with C is assumed. A knowledge of how integers are stored in memory is also useful, but not essential. ----[ 1.1 What is an integer? An integer, in the context of computing, is a variable capable of representing a real number with no fractional part. Integers are typically the same size as a pointer on the system they are compiled on (i.e. on a 32 bit system, such as i386, an integer is 32 bits long, on a 64 bit system, such as SPARC, an integer is 64 bits long). Some compilers don't use integers and pointers of the same size however, so for the sake of simplicity all the examples refer to a 32 bit system with 32 bit integers, longs and pointers. Integers, like all variables are just regions of memory. When we talk about integers, we usually represent them in decimal, as that is the numbering system humans are most used to. Computers, being digital, cannot deal with decimal, so internally to the computer integers are stored in binary. Binary is another system of representing numbers which uses only two numerals, 1 and 0, as opposed to the ten numerals used in decimal. As well as binary and decimal, hexadecimal (base sixteen) is often used in computing as it is very easy to convert between binary and hexadecimal. Since it is often necessary to store negative numbers, there needs to be a mechanism to represent negative numbers using only binary. The way this is accomplished is by using the most significant bit (MSB) of a variable to determine the sign: if the MSB is set to 1, the variable is interpreted as negative; if it is set to 0, the variable is positive. This can cause some confusion, as will be explained in the section on signedness bugs, because not all variables are signed, meaning they do not all use the MSB to determine whether they are positive or negative. These variable are known as unsigned and can only be assigned positive values, whereas variables which can be either positive or negative are called unsigned. ----[ 1.2 What is an integer overflow? Since an integer is a fixed size (32 bits for the purposes of this paper), there is a fixed maximum value it can store. When an attempt is made to store a value greater than this maximum value it is known as an integer overflow. The ISO C99 standard says that an integer overflow causes "undefined behaviour", meaning that compilers conforming to the standard may do anything they like from completely ignoring the overflow to aborting the program. Most compilers seem to ignore the overflow, resulting in an unexpected or erroneous result being stored. ----[ 1.3 Why can they be dangerous? Integer overflows cannot be detected after they have happened, so there is not way for an application to tell if a result it has calculated previously is in fact correct. This can get dangerous if the calculation has to do with the size of a buffer or how far into an array to index. Of course most integer overflows are not exploitable because memory is not being directly overwritten, but sometimes they can lead to other classes of bugs, frequently buffer overflows. As well as this, integer overflows can be difficult to spot, so even well audited code can spring surprises. --[ 2.0 Integer overflows So what happens when an integer overflow does happen? ISO C99 has this to say: "A computation involving unsigned operands can never overflow, because a result that cannot be represented by the resulting unsigned integer type is reduced modulo the number that is one greater than the largest value that can be represented by the resulting type." NB: modulo arithmetic involves dividing two numbers and taking the remainder, e.g. 10 modulo 5 = 0 11 modulo 5 = 1 so reducing a large value modulo (MAXINT + 1) can be seen as discarding the portion of the value which cannot fit into an integer and keeping the rest. In C, the modulo operator is a % sign. </NB> This is a bit wordy, so maybe an example will better demonstrate the typical "undefined behaviour": We have two unsigned integers, a and b, both of which are 32 bits long. We assign to a the maximum value a 32 bit integer can hold, and to b we assign 1. We add a and b together and store the result in a third unsigned 32 bit integer called r: a = 0xffffffff b = 0x1 r = a + b Now, since the result of the addition cannot be represented using 32 bits, the result, in accordance with the ISO standard, is reduced modulo 0x100000000. r = (0xffffffff + 0x1) % 0x100000000 r = (0x100000000) % 0x100000000 = 0 Reducing the result using modulo arithmetic basically ensures that only the lowest 32 bits of the result are used, so integer overflows cause the result to be truncated to a size that can be represented by the variable. This is often called a "wrap around", as the result appears to wrap around to 0. ----[ 2.1 Widthness overflows So an integer overflow is the result of attempting to store a value in a variable which is too small to hold it. The simplest example of this can be demonstrated by simply assigning the contents of large variable to a smaller one: /* ex1.c - loss of precision */ #include <stdio.h> int main(void){ int l; short s; char c; l = 0xdeadbeef; s = l; c = l; printf("l = 0x%x (%d bits)\n", l, sizeof(l) * 8); printf("s = 0x%x (%d bits)\n", s, sizeof(s) * 8); printf("c = 0x%x (%d bits)\n", c, sizeof(c) * 8); return 0; } /* EOF */ The output of which looks like this: nova:signed {48} ./ex1 l = 0xdeadbeef (32 bits) s = 0xffffbeef (16 bits) c = 0xffffffef (8 bits) Since each assignment causes the bounds of the values that can be stored in each type to be exceeded, the value is truncated so that it can fit in the variable it is assigned to. It is worth mentioning integer promotion here. When a calculation involving operands of different sizes is performed, the smaller operand is "promoted" to the size of the larger one. The calculation is then performed with these promoted sizes and, if the result is to be stored in the smaller variable, the result is truncated to the smaller size again. For example: int i; short s; s = i; A calculation is being performed with different sized operands here. What happens is that the variable s is promoted to an int (32 bits long), then the contents of i is copied into the new promoted s. After this, the contents of the promoted variable are "demoted" back to 16 bits in order to be saved in s. This demotion can cause the result to be truncated if it is greater than the maximum value s can hold. ------[ 2.1.1 Exploiting Integer overflows are not like most common bug classes. They do not allow direct overwriting of memory or direct execution flow control, but are much more subtle. The root of the problem lies in the fact that there is no way for a process to check the result of a computation after it has happened, so there may be a discrepancy between the stored result and the correct result. Because of this, most integer overflows are not actually exploitable. Even so, in certain cases it is possible to force a crucial variable to contain an erroneous value, and this can lead to problems later in the code. Because of the subtlety of these bugs, there is a huge number of situations in which they can be exploited, so I will not attempt to cover all exploitable conditions. Instead, I will provide examples of some situations which are exploitable, in the hope of inspiring the reader in their own research Example 1: /* width1.c - exploiting a trivial widthness bug */ #include <stdio.h> #include <string.h> int main(int argc, char *argv[]){ unsigned short s; int i; char buf[80]; if(argc < 3){ return -1; } i = atoi(argv[1]); s = i; if(s >= 80){ /* [w1] */ printf("Oh no you don't!\n"); return -1; } printf("s = %d\n", s); memcpy(buf, argv[2], i); buf[i] = '\0'; printf("%s\n", buf); return 0; } While a construct like this would probably never show up in real life code, it serves well as an example. Take a look at the following inputs: nova:signed {100} ./width1 5 hello s = 5 hello nova:signed {101} ./width1 80 hello Oh no you don't! nova:signed {102} ./width1 65536 hello s = 0 Segmentation fault (core dumped) The length argument is taken from the command line and held in the integer i. When this value is transferred into the short integer s, it is truncated if the value is too great to fit into s (i.e. if the value is greater than 65535). Because of this, it is possible to bypass the bounds check at [w1] and overflow the buffer. After this, standard stack smashing techniques can be used to exploit the process. ----[ 2.2 Arithmetic overflows As shown in section 2.0, if an attempt is made to store a value in an integer which is greater than the maximum value the integer can hold, the value will be truncated. If the stored value is the result of an arithmetic operation, any part of the program which later uses the result will run incorrectly as the result of the arithmetic being incorrect. Consider this example demonstrating the wrap around shown earlier: /* ex2.c - an integer overflow */ #include <stdio.h> int main(void){ unsigned int num = 0xffffffff; printf("num is %d bits long\n", sizeof(num) * 8); printf("num = 0x%x\n", num); printf("num + 1 = 0x%x\n", num + 1); return 0; } /* EOF */ The output of this program looks like this: nova:signed {4} ./ex2 num is 32 bits long num = 0xffffffff num + 1 = 0x0 Note: The astute reader will have noticed that 0xffffffff is decimal -1, so it appears that we're just doing 1 + (-1) = 0 Whilst this is one way at looking at what's going on, it may cause some confusion since the variable num is unsigned and therefore all arithmetic done on it will be unsigned. As it happens, a lot of signed arithmetic depends on integer overflows, as the following demonstrates (assume both operands are 32 bit variables): -700 + 800 = 100 0xfffffd44 + 0x320 = 0x100000064 Since the result of the addition exceeds the range of the variable, the lowest 32 bits are used as the result. These low 32 bits are 0x64, which is equal to decimal 100. </note> Since an integer is signed by default, an integer overflow can cause a change in signedness which can often have interesting effects on subsequent code. Consider the following example: /* ex3.c - change of signedness */ #include <stdio.h> int main(void){ int l; l = 0x7fffffff; printf("l = %d (0x%x)\n", l, l); printf("l + 1 = %d (0x%x)\n", l + 1 , l + 1); return 0; } /* EOF */ The output of which is: nova:signed {38} ./ex3 l = 2147483647 (0x7fffffff) l + 1 = -2147483648 (0x80000000) Here the integer is initialised with the highest positive value a signed long integer can hold. When it is incremented, the most significant bit (indicating signedness) is set and the integer is interpreted as being negative. Addition is not the only arithmetic operation which can cause an integer to overflow. Almost any operation which changes the value of a variable can cause an overflow, as demonstrated in the following example: /* ex4.c - various arithmetic overflows */ #include <stdio.h> int main(void){ int l, x; l = 0x40000000; printf("l = %d (0x%x)\n", l, l); x = l + 0xc0000000; printf("l + 0xc0000000 = %d (0x%x)\n", x, x); x = l * 0x4; printf("l * 0x4 = %d (0x%x)\n", x, x); x = l - 0xffffffff; printf("l - 0xffffffff = %d (0x%x)\n", x, x); return 0; } /* EOF */ Output: nova:signed {55} ./ex4 l = 1073741824 (0x40000000) l + 0xc0000000 = 0 (0x0) l * 0x4 = 0 (0x0) l - 0xffffffff = 1073741825 (0x40000001) The addition is causing an overflow in exactly the same way as the first example, and so is the multiplication, although it may seem different. In both cases the result of the arithmetic is too great to fit in an integer, so it is reduced as described above. The subtraction is slightly different, as it is causing an underflow rather than an overflow: an attempt is made to store a value lower than the minimum value the integer can hold, causing a wrap around. In this way we are able to force an addition to subtract, a multiplication to divide or a subtraction to add. ------[ 2.2.1 Exploiting One of the most common ways arithmetic overflows can be exploited is when a calculation is made about how large a buffer must be allocated. Often a program must allocate space for an array of objects, so it uses the malloc(3) or calloc(3) routines to reserve the space and calculates how much space is needed by multiplying the number of elements by the size of an object. As has been previously shown, if we are able to control either of these operands (number of elements or object size) we may be able to mis-size the buffer, as the following code fragment shows: int myfunction(int *array, int len){ int *myarray, i; myarray = malloc(len * sizeof(int)); /* [1] */ if(myarray == NULL){ return -1; } for(i = 0; i < len; i++){ /* [2] */ myarray[i] = array[i]; } return myarray; } This seemingly innocent function could bring about the downfall of a system due to its lack of checking of the len parameter. The multiplication at [1] can be made to overflow by supplying a high enough value for len, so we can force the buffer to be any length we choose. By choosing a suitable value for len, we can cause the loop at [2] to write past the end of the myarray buffer, resulting in a heap overflow. This could be leveraged into executing arbitrary code on certain implementations by overwriting malloc control structures, but that is beyond the scope of this article. Another example: int catvars(char *buf1, char *buf2, unsigned int len1, unsigned int len2){ char mybuf[256]; if((len1 + len2) > 256){ /* [3] */ return -1; } memcpy(mybuf, buf1, len1); /* [4] */ memcpy(mybuf + len1, buf2, len2); do_some_stuff(mybuf); return 0; } In this example, the check at [3] can be bypassed by using suitable values for len1 and len2 that will cause the addition to overflow and wrap around to a low number. For example, the following values: len1 = 0x104 len2 = 0xfffffffc when added together would result in a wrap around with a result of 0x100 (decimal 256). This would pass the check at [3], then the memcpy(3)'s at [4] would copy data well past the end of the buffer. --[ 3 Signedness Bugs Signedness bugs occur when an unsigned variable is interpreted as signed, or when a signed variable is interpreted as unsigned. This type of behaviour can happen because internally to the computer, there is no distinction between the way signed and unsigned variables are stored. Recently, several signedness bugs showed up in the FreeBSD and OpenBSD kernels, so there are many examples readily available. ----[ 3.1 What do they look like? Signedness bugs can take a variety of forms, but some of the things to look out for are: * signed integers being used in comparisons * signed integers being used in arithmetic * unsigned integers being compared to signed integers Here is classic example of a signedness bug: int copy_something(char *buf, int len){ char kbuf[800]; if(len > sizeof(kbuf)){ /* [1] */ return -1; } return memcpy(kbuf, buf, len); /* [2] */ } The problem here is that memcpy takes an unsigned int as the len parameter, but the bounds check performed before the memcpy is done using signed integers. By passing a negative value for len, it is possible to pass the check at [1], but then in the call to memcpy at [2], len will be interpeted as a huge unsigned value, causing memory to be overwritten well past the end of the buffer kbuf. Another problem that can stem from signed/unsigned confusion occurs when arithmetic is performed. Consider the following example: int table[800]; int insert_in_table(int val, int pos){ if(pos > sizeof(table) / sizeof(int)){ return -1; } table[pos] = val; return 0; } Since the line table[pos] = val; is equivalent to *(table + (pos * sizeof(int))) = val; we can see that the problem here is that the code does not expect a negative operand for the addition: it expects (table + pos) to be greater than table, so providing a negative value for pos causes a situation which the program does not expect and can therefore not deal with. ------[ 3.1.1 Exploiting This class of bug can be problematic to exploit, due to the fact that signed integers, when interpreted as unsigned, tend to be huge. For example, -1 when represented in hexadecimal is 0xffffffff. When interpreted as unsiged, this becomes the greatest value it is possible to represent in an integer (4,294,967,295), so if this value is passed to mempcpy as the len parameter (for example), memcpy will attempt to copy 4GB of data to the destination buffer. Obviously this is likely to cause a segfault or, if not, to trash a large amount of the stack or heap. Sometimes it is possible to get around this problem by passing a very low value for the source address and hope, but this is not always possible. ----[ 3.2 Signedness bugs caused by integer overflows Sometimes, it is possible to overflow an integer so that it wraps around to a negative number. Since the application is unlikely to expect such a value, it may be possible to trigger a signedness bug as described above. An example of this type of bug could look like this: int get_two_vars(int sock, char *out, int len){ char buf1[512], buf2[512]; unsigned int size1, size2; int size; if(recv(sock, buf1, sizeof(buf1), 0) < 0){ return -1; } if(recv(sock, buf2, sizeof(buf2), 0) < 0){ return -1; } /* packet begins with length information */ memcpy(&size1, buf1, sizeof(int)); memcpy(&size2, buf2, sizeof(int)); size = size1 + size2; /* [1] */ if(size > len){ /* [2] */ return -1; } memcpy(out, buf1, size1); memcpy(out + size1, buf2, size2); return size; } This example shows what can sometimes happen in network daemons, especially when length information is passed as part of the packet (in other words, it is supplied by an untrusted user). The addition at [1], used to check that the data does not exceed the bounds of the output buffer, can be abused by setting size1 and size2 to values that will cause the size variable to wrap around to a negative value. Example values could be: size1 = 0x7fffffff size2 = 0x7fffffff (0x7fffffff + 0x7fffffff = 0xfffffffe (-2)). When this happens, the bounds check at [2] passes, and a lot more of the out buffer can be written to than was intended (in fact, arbitrary memory can be written to, as the (out + size1) dest parameter in the second memcpy call allows us to get to any location in memory). These bugs can be exploited in exactly the same way as regular signedness bugs and have the same problems associated with them - i.e. negative values translate to huge positive values, which can easily cause segfaults. --[ 4 Real world examples There are many real world applications containing integer overflows and signedness bugs, particularly network daemons and, frequently, in operating system kernels. ----[ 4.1 Integer overflows This (non-exploitable) example was taken from a security module for linux. This code runs in the kernel context: int rsbac_acl_sys_group(enum rsbac_acl_group_syscall_type_t call, union rsbac_acl_group_syscall_arg_t arg) { ... switch(call) { case ACLGS_get_group_members: if( (arg.get_group_members.maxnum <= 0) /* [A] */ || !arg.get_group_members.group ) { ... rsbac_uid_t * user_array; rsbac_time_t * ttl_array; user_array = vmalloc(sizeof(*user_array) * arg.get_group_members.maxnum); /* [B] */ if(!user_array) return -RSBAC_ENOMEM; ttl_array = vmalloc(sizeof(*ttl_array) * arg.get_group_members.maxnum); /* [C] */ if(!ttl_array) { vfree(user_array); return -RSBAC_ENOMEM; } err = rsbac_acl_get_group_members(arg.get_group_members.group, user_array, ttl_array, arg.get_group_members.max num); ... } In this example, the bounds checking at [A] is not sufficient to prevent the integer overflows at and [C]. By passing a high enough (i.e. greater than 0xffffffff / 4) value for arg.get_group_members.maxnum, we can cause the multiplications at and [C] to overflow and force the buffers ttl_array and user_array to be smaller than the application expects. Since rsbac_acl_get_group_members copies user controlled data to these buffers, it is possible to write past the end of the user_array and ttl_array buffers. In this case, the application used vmalloc() to allocate the buffers, so an attempt to write past the end of the buffers will simply raise an error, so it cannot be exploited. Even so, it provides an example of what these bugs can look like in real code. Another example of a recent real world integer overflow vulnerability was the problem in the XDR RPC library (discovered by ISS X-Force). In this case, user supplied data was used in the calculation of the size of a dynamically allocated buffer which was filled with user supplied data. The vulnerable code was this: bool_t xdr_array (xdrs, addrp, sizep, maxsize, elsize, elproc) XDR *xdrs; caddr_t *addrp; /* array pointer */ u_int *sizep; /* number of elements */ u_int maxsize; /* max numberof elements */ u_int elsize; /* size in bytes of each element */ xdrproc_t elproc; /* xdr routine to handle each element */ { u_int i; caddr_t target = *addrp; u_int c; /* the actual element count */ bool_t stat = TRUE; u_int nodesize; ... c = *sizep; if ((c > maxsize) && (xdrs->x_op != XDR_FREE)) { return FALSE; } nodesize = c * elsize; /* [1] */ ... *addrp = target = mem_alloc (nodesize); /* [2] */ ... for (i = 0; (i < c) && stat; i++) { stat = (*elproc) (xdrs, target, LASTUNSIGNED); /* [3] */ target += elsize; } As you can see, by supplying large values for elsize and c (sizep), it was possible to cause the multiplication at [1] to overflow and cause nodesize to be much smaller than the application expected. Since nodesize was then used to allocate a buffer at [2], the buffer could be mis-sized leading to a heap overflow at [3]. For more information on this hole, see the CERT advisory listed in the appendix. ----[ 4.2 Signedness bugs Recently, several signedness bugs were brought to light in the freebsd kernel. These allowed large portions of kernel memory to be read by passing negative length paramters to various syscalls. The getpeername(2) function had such a problem and looked like this: static int getpeername1(p, uap, compat) struct proc *p; register struct getpeername_args /* { int fdes; caddr_t asa; int *alen; } */ *uap; int compat; { struct file *fp; register struct socket *so; struct sockaddr *sa; int len, error; ... error = copyin((caddr_t)uap->alen, (caddr_t)&len, sizeof (len)); if (error) { fdrop(fp, p); return (error); } ... len = MIN(len, sa->sa_len); /* [1] */ error = copyout(sa, (caddr_t)uap->asa, (u_int)len); if (error) goto bad; gotnothing: error = copyout((caddr_t)&len, (caddr_t)uap->alen, sizeof (len)); bad: if (sa) FREE(sa, M_SONAME); fdrop(fp, p); return (error); } This is a classic example of a signedness bug - the check at [1] did not take into account the fact that len could be negative, in which case the MIN macro would always return len. When this negative len parameter was passed to copyout, it was interpretted as a huge positive integer which caused copyout to copy up to 4GB of kernel memory to user space. --[ Conclusion Integer overflows can be extremely dangerous, partly because it is impossible to detect them after they have happened. If an integer overflow takes place, the application cannot know that the calculation it has performed is incorrect, and it will continue under the assumption that it is. Even though they can be difficult to exploit, and frequently cannot be exploited at all, they can cause unepected behaviour, which is never a good thing in a secure system. --[ Appendix CERT advisory on the XDR bug: CERT Advisory CA-2002-25 Integer Overflow In XDR Library FreeBSD advisory: Advisory: Boundary checking errors involving signed integers |=[ EOF ]=---------------------------------------------------------------=| Sursa Mai uitati-va pe phrack.com pentru ca aveti de invatat chestii interesante.
      • 1
      • Upvote
×
×
  • Create New...