To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
VBForums  

VB Wire News
Article :: Building Dynamic Systems with Expressions in .NET
How Is XML Like An Interface?
Understanding Covariance and Contravariance
Print VS 2010 Keyboard Shortcut References in Letter (8.5x11in) and A4 (210×297mm) Sizes
Updated Productivity Power Tools



Go Back   VBForums > VBForums CodeBank > CodeBank - Visual Basic 6 and earlier

Reply Post New Thread
 
Thread Tools Display Modes
Old Aug 25th, 2005, 10:42 AM   #1
rm_03
Lively Member
 
rm_03's Avatar
 
Join Date: Aug 04
Posts: 92
rm_03  is on a distinguished road (30+)
VB6 - Process injection/API hooking

Part 1) IAT Hooking. All imported functions (like kernel32.sleep()) by a module
have an entry in its IAT (Import Address Table). By comparing the entry point of the
target function with all the entries in the IAT, you can overwrite the IAT entry with a new function pointer.
Next time the importing module calls the target function, it will be redirected to the new function.

Part 2) Function redirection. By overwriting a function with a JMP instruction you can redirect any function to a new one.

Part 3) Process injection and remote API hooking.
You can inject any module into a process by getting its size (=> PE header),
allocating memory in the remote process
and copy the whole module with WriteProcessMemory() to the remote process.
The aim now is to hook an API in the remote process.
Because CreateRemoteThread() will cause VB code to run in a new thread (not good, as we all know),
we simply do the same thing like in part 2, but with WriteProcessMemory().

Note: The remote process needs to be written in VB, too.
Attached Files
File Type: zip IAT.zip (5.3 KB, 2892 views)
File Type: zip RedirectHook.zip (3.5 KB, 2767 views)
File Type: zip Inject_en.zip (6.6 KB, 3438 views)
rm_03 is offline   Reply With Quote
Old Sep 4th, 2005, 12:45 PM   #2
moeur
Old Member
 
moeur's Avatar
 
Join Date: Nov 04
Location: In Hiding.... Weather: sizzzzlin'........ Code: Secret
Posts: 2,701
moeur is a glorious beacon of light (400+)moeur is a glorious beacon of light (400+)moeur is a glorious beacon of light (400+)moeur is a glorious beacon of light (400+)moeur is a glorious beacon of light (400+)
Re: VB6 - Process injection/API hooking

Perhaps you could explain a little bit more about what you are doing here. For example let's discuss #3. The example program when run shows all running processes. I assume you are supposed to highlight a processes let's say calc.exe, and click inject. Of course injection fails (in german) because I did something wrong.

Edit: i just saw the end of the post, the remote process needs to be written in VB. Why is that?
moeur is offline   Reply With Quote
Old Sep 4th, 2005, 01:02 PM   #3
rm_03
Lively Member
 
rm_03's Avatar
 
Join Date: Aug 04
Posts: 92
rm_03  is on a distinguished road (30+)
Re: VB6 - Process injection/API hooking

Quote:
Perhaps you could explain a little bit more about what you are doing here
I'm afraid of writing long messages, not so much practice in writing English

Because of the runtime.
Almost every function you use (like the left/right/mid functions) is stored in the runtime,
but I guess, you know that.
When starting a VB app, the runtime does some stuff I don't really know about, which won't allow you to use these functions in a new thread (sure, with some tricks you can, but they're not safe, At least in a standard exe).
You could inject the VB runtime into the other process, but there's the risk that the address space is already used by another module.
But even if it worked - it wouldn't be initialized.

So what I did in example 3 was:
1) Overwrite the remote function with a JMP instruction
2) inject my own module to the remote process
but don't execute code with CreateRemoteThread
because it will executed in the first thread when the hooked API will be called.
rm_03 is offline   Reply With Quote
Old Sep 5th, 2005, 07:41 AM   #4
penagate
Super Moderator
 
Join Date: Jan 05
Location: Sunny Adelaide
Posts: 12,716
penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)
Re: VB6 - Process injection/API hooking

Quote:
Originally Posted by rm_03
Because of the runtime.
Sounds familiar moeur
penagate is offline   Reply With Quote
Old Dec 5th, 2005, 08:49 PM   #5
unruledboy
Junior Member
 
Join Date: Dec 05
Posts: 21
unruledboy is an unknown quantity at this point (<10)
Re: VB6 - Process injection/API hooking

is it possible to hook CreateProcess/OpenProcess/CreateThread etc APIs in Kernel32.dll for shell32.dll module? I wish to intercept the execution of apps, before they really start to run, I need to decide whether I should let them run.
unruledboy is offline   Reply With Quote
Old Dec 5th, 2005, 11:23 PM   #6
moeur
Old Member
 
moeur's Avatar
 
Join Date: Nov 04
Location: In Hiding.... Weather: sizzzzlin'........ Code: Secret
Posts: 2,701
moeur is a glorious beacon of light (400+)moeur is a glorious beacon of light (400+)moeur is a glorious beacon of light (400+)moeur is a glorious beacon of light (400+)moeur is a glorious beacon of light (400+)
Re: VB6 - Process injection/API hooking

see this thread on how you can do that
http://www.vbforums.com/showthread.php?t=324133
moeur is offline   Reply With Quote
Old Dec 5th, 2005, 11:37 PM   #7
unruledboy
Junior Member
 
Join Date: Dec 05
Posts: 21
unruledboy is an unknown quantity at this point (<10)
Smile Re: VB6 - Process injection/API hooking

yes, I've already read all threads realted to hook/inject etc. but some uses external dlls(third party ones), or uses vc++.

I wish to have all done in pure vb6
unruledboy is offline   Reply With Quote
Old Jul 7th, 2006, 02:36 AM   #8
abazabam
Hyperactive Member
 
Join Date: Jul 05
Posts: 400
abazabam is an unknown quantity at this point (<10)
Re: VB6 - Process injection/API hooking

Does anyone know how to intercept an API in all processes? The examples that I've seen only work with a specific process.
abazabam is offline   Reply With Quote
Old Jun 18th, 2008, 11:34 AM   #9
Ixiodor
New Member
 
Join Date: Jun 08
Posts: 1
Ixiodor is an unknown quantity at this point (<10)
Re: VB6 - Process injection/API hooking

A very good work but...there is a system for hook 1 API in all language?
This program if you hook a c++ program,the program crash T_T.
Can you explain me what change?
Ixiodor is offline   Reply With Quote
Old Dec 26th, 2009, 08:25 AM   #10
mustiback
Member
 
Join Date: Sep 08
Location: Turkey
Posts: 32
mustiback is an unknown quantity at this point (<10)
Re: VB6 - Process injection/API hooking

Redirecthook is not working...
Error : Variable not defined on RealAddr
mustiback is offline   Reply With Quote
Reply

Go Back   VBForums > VBForums CodeBank > CodeBank - Visual Basic 6 and earlier


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 08:04 PM.





Acceptable Use Policy

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.