Jump to content

IdinAK255

Active Members
  • Posts

    5
  • Joined

  • Last visited

Everything posted by IdinAK255

  1. I wish I thought of this earlier.
  2. I just realized there were some errors in my original code. Here's the working code. // Author: int main() from http://forums.hak5.org/ // Project name: Windows Site Redirector #include <stdio.h> #include <windows.h> #define BUFFER 100 // BUFFER is used to define the amount of bytes that should be allocated to each site's string value. #define NUM_SITES 1 // NUM_SITES indicates the number of sites you would like to redirect. void redirectSite(void); void main(void) { /* The two sets of if statements which follow disable the read only property of the hosts file and hide the folder which it's located in. This could be of use depending on what you are going to be using this program for... :0 */ if (GetFileAttributes("C:\\Windows\\System32\\drivers\\etc\\hosts") == FILE_ATTRIBUTE_READONLY) SetFileAttributes("C:\\Windows\\System32\\drivers\\etc\\hosts", FILE_ATTRIBUTE_NORMAL); if (GetFileAttributes("C:\\Windows\\System32\\drivers\\etc\\") != FILE_ATTRIBUTE_HIDDEN) SetFileAttributes("C:\\Windows\\System32\\drivers\\etc\\", FILE_ATTRIBUTE_HIDDEN); redirectSite(); } void redirectSite(void) { int i; /* intended_site is a two dimensional character array (string array) which is used to indicate the sites which you would like the user to be redirected from. For each site you must create two row elements in the array of these two forms. */ char intended_site[NUM_SITES * 2][BUFFER] = { "gmail.com", // Form 1: (sitenamegoeshere.com) "www.gmail.com" // Form 2: (www.sitenamegoeshere.com) }; /* redirected_site_ip is a two dimensional character array (string array) which is used to indicate the IP addresses of the sites which you would like the user to be redirected to. Make sure that each IP address in redirected_site_ip corresponds to the correct site in intended_site. */ char redirected_site_ip[NUM_SITES * 2][BUFFER] = { "IP address to be redirected to", "Same as above" }; FILE *hosts; hosts = fopen("C:\\Windows\\System32\\drivers\\etc\\hosts", "r+"); // Open the hosts file for writing. fseek(hosts, 0, SEEK_END); fprintf(hosts, "\n"); /* Writes the elements from intended_site and redirected_site_ip in the correct format into the hosts file. */ for (i = 0; i < NUM_SITES; i++) { fprintf(hosts, "%s\t%s\n", redirected_site_ip[i], intended_site[i]); } fclose(hosts); // Closes the hosts file. }
  3. Thanks. Also, I'm sorry for the lack of indentation in my code. I didn't realize that my code copied over without proper indentation until I posted it the topic.
  4. This project started out as a joke. I decided that I was going to make a program that blocked a certain online game which a friend of mine is absolutely addicted to. Then I took that program and modified it so that it would instead redirect the user to another website instead of just blocking it. I know it's not very hard to code such a program (took me a few minutes), but I thought I would give something back to the Hak5 forums because the show is just awesome. I just started watching nearly a week ago and I find it to be very interesting and informative. I'm constantly working on different projects and since it's almost summer time you can bet that I will be coding a lot. When I finish some of my more interesting projects I will post them here. Anyway, the source code is below. // Author: int main() from http://forums.hak5.org/ // Project name: Windows Site Redirector #include <stdio.h> #include <windows.h> #define BUFFER 100 // BUFFER is used to define the amount of bytes that should be allocated to each site's string value. #define NUM_SITES 1 // NUM_SITES indicates the number of sites you would like to redirect. void redirectSite(void); void main(void) { /* The two sets of if statements which follow disable the read only property of the hosts file and hide the folder which it's located in. These could be of use if you depending on what you are going to be using this program for... :0 */ if (GetFileAttributes("C:\\Windows\\System32\\drivers\\etc\\hosts") == FILE_ATTRIBUTE_READONLY) SetFileAttributes("C:\\Windows\\System32\\drivers\\etc\\hosts", FILE_ATTRIBUTE_NORMAL); if (GetFileAttributes("C:\\Windows\\System32\\drivers\\etc\\") != FILE_ATTRIBUTE_HIDDEN) SetFileAttributes("C:\\Windows\\System32\\drivers\\etc\\", FILE_ATTRIBUTE_HIDDEN); redirectSite(); } void redirectSite(void) { int i; /* intended_site is a two dimensional character array (string array) which is used to indicate the sites which you would like the user to be redirected from. For each site you must create two row elements in the array of these two forms. */ char intended_site[NUM_SITES * 2][bUFFER] { "gmail.com", // Form 1: (sitenamegoeshere.com) "www.gmail.com" // Form 2: (www.sitenamegoeshere.com) }; /* redirected_site_ip is a two dimensional character array (string array) which is used to indicate the IP addresses of the sites which you would like the user to be redirected to. Make sure that each IP address in redirected_site_ip corresponds to the correct site in intended_site. */ char redirected_site_ip[NUM_SITES * 2][bUFFER] { "IP address to be redirected to", "Same as above" } FILE *hosts; hosts = fopen("C:\\Windows\\System32\\drivers\\etc\\hosts", "r+"); // Open the hosts file for writing. fseek(hosts, 0, SEEK_END); fprintf(hosts, "\n"); /* Writes the elements from intended_site and redirected_site_ip in the correct format into the hosts file. */ for (i = 0; i < NUM_SITES; i++) { fprintf(hosts, "%s\t%s\n", redirected_site_ip, intended_site); } fclose(hosts); // Closes the hosts file. }
×
×
  • Create New...