Hello fellow members,
I know there are million others who are out of ideas to code, like me. After a little bit of searching, I have found a link in which it contains some C++ exercises and solutions for those exercises. Remember that the exercises are arranged from difficulty; If you want the hard ones, scroll all the way to the bottom.
Ordered based on difficulty(really easy for beginner programmers): http://en.wikibooks.org/wiki/C++_Program...Iterations
A lot of exercises!: http://en.wikibooks.org/wiki/C%2B%2B_Pro.../Exercises
Not ordered in any way: http://www.fz-juelich.de/video/cpp/html/exercises.html
The most famous, ProjectEuler: http://projecteuler.net/index.php?section=problems
I hope you found this helpful. Please if you have any ideas or websites which contains some programming ideas, feel free to post them.
Thanks for reading,
Showing posts with label C. Show all posts
Showing posts with label C. Show all posts
Sunday, September 8, 2013
Friday, September 6, 2013
C++ Send EMail + Win32 w/ Download
Hello fellow coders,
![[Image: dm-613784255382.png]](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_tAz2hMg_Jo05kpmSmyTqsfka5Grmspe-BW0OuHowMvTnqMqHujGxpBZGvmtW84XkZ8SpznCVHTJjaPPy2PLkiFDw3_wy08tkweEwhsZPY=s0-d)
It is coded purely C/C++.
Also, the part that consumed most of my time in this project was base64 encryption. I was initially thinking of just ripping one online but couldn't. All the sources used external libraries and if you know me, I hate doing that. Not to mention, I had no patience to read over the external library and copy/paste it and adjust to the modifications of my project.
So I went ahead and implemented my own retarded base64 encryption, which works fine. I followed this: Base64 Wikipedia
It's pretty simple and VERY basic.
Basic outline of the program:
The commands above are the ones sent to GMail server. That's all that's needed to send an EMail along with base64 encoder.
oh also, this is a very messy code, with little to no error handling. So, it's not perfect. It finishes its job though: send email. I didn't think about efficiency that much; I just wanted to get it done.
Download Link: http://uploading.com/e422f2f9/Emailer-rar
Source:
main.cpp
resource.rc
resource.h
Thanks and regards,
It is coded purely C/C++.
Also, the part that consumed most of my time in this project was base64 encryption. I was initially thinking of just ripping one online but couldn't. All the sources used external libraries and if you know me, I hate doing that. Not to mention, I had no patience to read over the external library and copy/paste it and adjust to the modifications of my project.
So I went ahead and implemented my own retarded base64 encryption, which works fine. I followed this: Base64 Wikipedia
It's pretty simple and VERY basic.
Basic outline of the program:
Code:
connect to smtp.gmail.com on port 25
Client: EHLO mail.gmail.com\r\n
Client: AUTH LOGIN\r\n
Client: base64 encrypted email\r\n
Client: base64 encrypted password\r\n
Server: 250 Accepted. --This is important to check.
Client: MAIL FROM: <emailid>\r\n
Client: RCPT TO: <toemailid>\r\n
DATA\r\n
Client: From: uremailid\r\n
Client: To: toemailid\r\n
Client: Subject: somesubject\r\n
Client: \r\n
Client: somemessageyouwanttosend\r\n
Client: .\r\n by sending period, it represents end of message.The commands above are the ones sent to GMail server. That's all that's needed to send an EMail along with base64 encoder.
oh also, this is a very messy code, with little to no error handling. So, it's not perfect. It finishes its job though: send email. I didn't think about efficiency that much; I just wanted to get it done.
Download Link: http://uploading.com/e422f2f9/Emailer-rar
Source:
main.cpp
resource.rc
resource.h
Thanks and regards,
Monday, September 2, 2013
Get Website Source + Source
Just a simple source, I would like to share. It can output the IP Addresses of as many websites as you pass through the command line.
Command-line:
Code:
#include <iostream>
#include <windows.h>
#pragma comment(lib, "ws2_32.lib")
int main(int argc, char *argv[])
{
WSADATA wsData;
if(WSAStartup(MAKEWORD(2, 2), &wsData) != 0)
{
std::cout << "Cannot WSAStartup\n";
WSACleanup();
}
else
{
for(int i = 1; i < argc; i++)
std::cout << argv[i] << " : " << inet_ntoa(*(in_addr*)*gethostbyname(argv[i])->h_addr_list) << std::endl;
}
std::cin.get();
return 0;
}Command-line:
Code:
Directory>GetWebAddress www.hackforums.net www.google.com www.youtube.com
www.hackforums.net : 69.162.82.251
www.google.com : 72.14.204.99
www.youtube.com : 74.125.113.92Saturday, August 31, 2013
-DLL Injection Source + Tutorial
Hello,
Full source present below. I am Sri Krishna. I have already posted this tutorial long back in Hackforums. I thought it would be nice to share it here.
Here is a quick explanation of how DLL injection works. The concept is very simple. This encompasses a lot of very useful functions. Very good knowledge.
DLL injection is not really injecting the DLL but to load the DLL inside the targeted process. The function that is used to load a DLL is [a href="http://msdn.microsoft.com/en-us/library/ms684175(v=vs.85).aspx"]LoadLibrary[/a]. LoadLibrary takes one argument which is the path of the DLL. We pretty much know how to load a DLL. Now, we need to understand how to make the targeted process load our DLL.
Let's look at it in this perspective: If you want to load a DLL in general, you would call LoadLibrary(DLL_PATH);, however, if you want to LoadLibrary(DLL_NAME); inside a process, you would have to execute that function inside the targeted process, correct? Well, Windows has provided us with useful functions that can help us perform this task. The functions we will be using are OpenProcess, VirtualAllocEx, WriteProcessMemory, and CreateRemoteThread.
We'll be using OpenProcess to open the target process. The information required to open the process is the Process ID(or PID). I suggest you look at the MSDN documentation for more information.
Here is what OpenProcess is asking:
Here is the actual code:
Now, hProcess contains the handle to the process, if OpenProcess doesn't return NULL. If OpenProcess returned NULL, then it failed. You can use [url=http://msdn.microsoft.com/en-us/library/ms679360(v=VS.85).aspx]GetLastError()[/url] function to get details of the failure.
Now, we need to allocate some memory in the targeted process for DLL path so we can pass it to LoadLibrary. We can do this by using VirtualAllocEx.
VirtualAllocEx might sound complicated but the arguments it takes are easy to understand and is perfect for this task. It's similar to malloc or new in C and C++, respectively. malloc/new only works in the process you are working with but with VirtualAllocEx you can "malloc" inside a target process!
What VirtualAllocEx is asking for:
That's essentially what it is asking us for. Now, lets follow along and legitimately fill in the arguments. Please, look up the MSDN Documention for MEM_RESERVE, MEM_COMMIT and PAGE_READWRITE for more information.
If the function suceeded, vAlloc will contain the base address where the allocation occured. If it failed, it will return NULL. Of course, you can use GetLastError to get more information about why the function failed.
Now, we will write the DLL path in the allocated memory. Now, where in memory region was the memory allocated? Well, vAlloc contains the base address of our memory, so we'll just use that to write our DLL path to. We can do this by using WriteProcessMemory.
This is what WriteProcessMemory is asking:
Now, lets write the actual code for the task:
If the function suceeded, it will return a non-zero integer. Of course, you can use GetLastError if it returned NULL.
Now, that we have everything up and ready for us to execute our LoadLibrary function inside the process, lets execute it!
We'll need CreateRemoteThread function to create a seperate thread for our LoadLibrary while not pausing the main process thread. CreateRemoteThread is similar to CreateThread except CreateRemoteThread takes one extra parameter which is the handle to the process(I'm sure you guessed it!). We'll pass in our hProcess for that parameter.
What CreateRemoteThread is asking:
Now, lets write the actual code for this task:
If the function failed, it will return NULL. Of course, you can check GetLastError() ;).
However, there are times, rarely, when this function will fail. It's probably because the kernel32.dll is not loaded in the process. This is a problem because kernel32.dll is DLL that provides us the function LoadLibrary. There is a way to fix this problem. You can use [url=http://msdn.microsoft.com/en-us/library/ms683212%28v=VS.85%29.aspx]GetProcAddress[/url] to get the address of LoadLibrary inside kernel32.dll and we can just call the address.
Here is what GetProcAddress is asking for:
Now, lets write the actual code:
If suceeded, pAddr will contain the address to LoadLibraryA. If it didn't suceed, it will return NULL and we can use GetLastError ;) Now, lets use this address and pass it to CreateRemoteThread.
After you finish creating the remote thread. Make sure to free the memory we have allocated using [url=http://msdn.microsoft.com/en-us/library/aa366894(v=vs.85).aspx]VirtualFreeEx[/url] and make sure to close the handle we have opened using OpenProcess using [url=http://msdn.microsoft.com/en-us/library/ms724211(v=VS.85).aspx]CloseHandle[/url].
Please check the MSDN documentation for more information. VirtualFreeEx is similar to free and delete in C and C++, respectively.
That's basically it! Now, you should, unless you don't speak English, understand how DLL injection works.
Here is the entire source of what we discussed; I added some error checking to help us out:
[url=http://pastebin.com/7AgCZAfx]DLL Injecton[/url]
Here is a source of a DLL to test if the Injector is working:
Here is an advanced version of DLL Injector. It opens up a file dialog box and it also lists the process with process IDs: http://pastebin.com/pC8JDVvV
Hope you learned something... Sri Krishna. Please, give me some feedback.
Full source present below. I am Sri Krishna. I have already posted this tutorial long back in Hackforums. I thought it would be nice to share it here.
Here is a quick explanation of how DLL injection works. The concept is very simple. This encompasses a lot of very useful functions. Very good knowledge.
DLL injection is not really injecting the DLL but to load the DLL inside the targeted process. The function that is used to load a DLL is [a href="http://msdn.microsoft.com/en-us/library/ms684175(v=vs.85).aspx"]LoadLibrary[/a]. LoadLibrary takes one argument which is the path of the DLL. We pretty much know how to load a DLL. Now, we need to understand how to make the targeted process load our DLL.
Let's look at it in this perspective: If you want to load a DLL in general, you would call LoadLibrary(DLL_PATH);, however, if you want to LoadLibrary(DLL_NAME); inside a process, you would have to execute that function inside the targeted process, correct? Well, Windows has provided us with useful functions that can help us perform this task. The functions we will be using are OpenProcess, VirtualAllocEx, WriteProcessMemory, and CreateRemoteThread.
We'll be using OpenProcess to open the target process. The information required to open the process is the Process ID(or PID). I suggest you look at the MSDN documentation for more information.
Here is what OpenProcess is asking:
OpenProcess(HowToOpen, InheritEverything(BOOL), Process ID);
Here is the actual code:
int ProcessID; std::cin >> ProcessID; HANDLE hProcess; //This will contain the handle to the process. hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, ProcessID);
Now, hProcess contains the handle to the process, if OpenProcess doesn't return NULL. If OpenProcess returned NULL, then it failed. You can use [url=http://msdn.microsoft.com/en-us/library/ms679360(v=VS.85).aspx]GetLastError()[/url] function to get details of the failure.
if(hProcess == NULL) std::cout << "OpenProcess: " << GetLastError(); else //continue
Now, we need to allocate some memory in the targeted process for DLL path so we can pass it to LoadLibrary. We can do this by using VirtualAllocEx.
VirtualAllocEx might sound complicated but the arguments it takes are easy to understand and is perfect for this task. It's similar to malloc or new in C and C++, respectively. malloc/new only works in the process you are working with but with VirtualAllocEx you can "malloc" inside a target process!
What VirtualAllocEx is asking for:
VirtualAllocEx(HandleToTheProcess, WhereDoYouWantToAllocate, HowMuchDoYouWantToAllocate, AllocationType, ProtectionType);
That's essentially what it is asking us for. Now, lets follow along and legitimately fill in the arguments. Please, look up the MSDN Documention for MEM_RESERVE, MEM_COMMIT and PAGE_READWRITE for more information.
LPVOID vAlloc; //Stores our base address where the allocation occured. vAlloc = VirtualAllocEx(hProcess, NULL, strlen(DLL_PATH) + 1, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); /*NULL in the second parameter lets the function choose where to allocate memory. We want to allocate the string length of DLL path, so we can write to it. It's strlen(DLL_PATH) +1 because of the null-terminator. Thanks to PoZHx for reminding me! :)*/
If the function suceeded, vAlloc will contain the base address where the allocation occured. If it failed, it will return NULL. Of course, you can use GetLastError to get more information about why the function failed.
Now, we will write the DLL path in the allocated memory. Now, where in memory region was the memory allocated? Well, vAlloc contains the base address of our memory, so we'll just use that to write our DLL path to. We can do this by using WriteProcessMemory.
This is what WriteProcessMemory is asking:
WriteProcessMemory(WhichProcess, WhereInMemory, WhatToWrite, HowLongIsTheData, HowMuchDidIWrite); //the last parameter is not really needed
Now, lets write the actual code for the task:
WriteProcessMemory(hProcess, vAlloc, DLL_PATH, strlen(DLL_PATH), NULL); //this will pretty much write the DLL path to the process.
If the function suceeded, it will return a non-zero integer. Of course, you can use GetLastError if it returned NULL.
Now, that we have everything up and ready for us to execute our LoadLibrary function inside the process, lets execute it!
We'll need CreateRemoteThread function to create a seperate thread for our LoadLibrary while not pausing the main process thread. CreateRemoteThread is similar to CreateThread except CreateRemoteThread takes one extra parameter which is the handle to the process(I'm sure you guessed it!). We'll pass in our hProcess for that parameter.
What CreateRemoteThread is asking:
CreateRemoteThread(HandleToProcess, ThreadAttributes, StackSize, FunctionToExecute, ParametersToFunction, Flags, ThreadID); /*For this task, we'll only worry about HandleToProcess, FunctionToExecute, and ParametersToFunction because that's all we need to execute our thread in the targeted process*/
Now, lets write the actual code for this task:
CreateRemoteThread(hProcess, NULL, NULL, (LPTHREAD_START_ROUTINE)LoadLibraryA, vAlloc, NULL, NULL);
If the function failed, it will return NULL. Of course, you can check GetLastError() ;).
However, there are times, rarely, when this function will fail. It's probably because the kernel32.dll is not loaded in the process. This is a problem because kernel32.dll is DLL that provides us the function LoadLibrary. There is a way to fix this problem. You can use [url=http://msdn.microsoft.com/en-us/library/ms683212%28v=VS.85%29.aspx]GetProcAddress[/url] to get the address of LoadLibrary inside kernel32.dll and we can just call the address.
Here is what GetProcAddress is asking for:
GetProcAddress(HandleToTheModuleWhereTheFunctionIsLocated, FunctionName);
Now, lets write the actual code:
LPVOID pAddr; //This will contain the address of LoadLibrary, if suceeded.
pAddr = GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA");
If suceeded, pAddr will contain the address to LoadLibraryA. If it didn't suceed, it will return NULL and we can use GetLastError ;) Now, lets use this address and pass it to CreateRemoteThread.
CreateRemoteThread(hProcess, NULL, NULL, (LPTHREAD_START_ROUTINE)pAddr, vAlloc, NULL, NULL);
After you finish creating the remote thread. Make sure to free the memory we have allocated using [url=http://msdn.microsoft.com/en-us/library/aa366894(v=vs.85).aspx]VirtualFreeEx[/url] and make sure to close the handle we have opened using OpenProcess using [url=http://msdn.microsoft.com/en-us/library/ms724211(v=VS.85).aspx]CloseHandle[/url].
Please check the MSDN documentation for more information. VirtualFreeEx is similar to free and delete in C and C++, respectively.
VirtualFreeEx(hProcess, vAlloc, NULL, MEM_RELEASE); //Must call this before closing handle. CloseHandle(hProcess);
That's basically it! Now, you should, unless you don't speak English, understand how DLL injection works.
Here is the entire source of what we discussed; I added some error checking to help us out:
[url=http://pastebin.com/7AgCZAfx]DLL Injecton[/url]
Here is a source of a DLL to test if the Injector is working:
#include <windows.h>
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD dwReason, LPVOID lpReserved)
{
if(dwReason == DLL_PROCESS_ATTACH)
MessageBox(NULL, "Injected to process!", "Injected!", MB_OK);
return true;
}
Here is an advanced version of DLL Injector. It opens up a file dialog box and it also lists the process with process IDs: http://pastebin.com/pC8JDVvV
Hope you learned something... Sri Krishna. Please, give me some feedback.
Subscribe to:
Posts (Atom)