Author Topic: [C] Making A Website Blocker With Manifest  (Read 2243 times)

0 Members and 2 Guests are viewing this topic.

Offline The Alchemist

  • Peasant
  • *
  • Posts: 100
  • Cookies: 18
  • Cult Of Personality
    • View Profile
    • Scriptings - Paste Tool
[C] Making A Website Blocker With Manifest
« on: April 12, 2014, 03:37:04 pm »
I'm trying to make a website blocker that runs with administrator privileges.
Here is my C code : http://www.scriptings.tk/paste/5348fab7a1ee5
Or view it here :
Code: (c) [Select]
#include<stdio.h>
#include<conio.h>
void main()
{
    FILE* handler;
    int i;
    char* str = "127.0.0.1       ";
    char site[25];
    handler   = fopen("C:\\\\Windows\\System32\\drivers\\etc\\hosts","a");
    do
    {
        printf("Enter site : ");
        fflush(stdin);
        gets(site);
        fputs(str, handler);
        fputs(site, handler);
        fputs("\n", handler);
        printf("Enter 1 to continue : ");
        scanf("%d",&i);
    } while(i == 1);
    fclose(handler);
    getch();
}
Here is my manifest file : http://www.scriptings.tk/paste/5348fb172bbd8
OR view it here :
Code: (xml) [Select]
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <ms_asmv2:trustInfo xmlns:ms_asmv2="urn:schemas-microsoft-
     com:asm.v2">
    <ms_asmv2:security>
      <ms_asmv2:requestedPrivileges>
        <ms_asmv2:requestedExecutionLevel level="requiredAdministrator">
        </ms_asmv2:requestedExecutionLevel>
      </ms_asmv2:requestedPrivileges>
    </ms_asmv2:security>
  </ms_asmv2:trustInfo>
</assembly>

Im using Microsoft Visual Studio 2010. Its getting Built completely and asking for administrator privileges while executing. But when I run the exe, an error comes up :


How do I solve this problem? Is this something thats happening due to Windows 7 firewall or something?
Please guys, help me out with this.
Defeat the best... To be the best...

Offline Kulverstukas

  • Administrator
  • Zeus
  • *
  • Posts: 6627
  • Cookies: 542
  • Fascist dictator
    • View Profile
    • My blog
Re: [C] Making A Website Blocker With Manifest
« Reply #1 on: April 12, 2014, 03:43:58 pm »
Don't use that shitty MS visual studio crap. I recommend CodeBlocks or C++Builder.

Offline The Alchemist

  • Peasant
  • *
  • Posts: 100
  • Cookies: 18
  • Cult Of Personality
    • View Profile
    • Scriptings - Paste Tool
Re: [C] Making A Website Blocker With Manifest
« Reply #2 on: April 12, 2014, 04:03:30 pm »
Don't use that shitty MS visual studio crap. I recommend CodeBlocks or C++Builder.
Ok, I'll use Codeblocks if I can add manifest using that. What will be the solution to the problem?
The stream you try to manipulate is obviously null, check if the fopen succeeded (line 9)
Yeah, fopen() isn't succeeding I think.
Defeat the best... To be the best...

Offline 0poitr

  • Peasant
  • *
  • Posts: 149
  • Cookies: 64
    • View Profile
Re: [C] Making A Website Blocker With Manifest
« Reply #3 on: April 12, 2014, 05:28:41 pm »
I'm trying to make a website blocker that runs with administrator privileges.
Here is my C code : http://www.scriptings.tk/paste/5348fab7a1ee5
Or view it here :
Code: (c) [Select]
#include<stdio.h>
#include<conio.h>
void main()
{
   
    char* str = "127.0.0.1       ";
   
        fputs(str, handler);
     
}
The memory for str is allocated statically off the stack. It's read-only. You can't re-assign a value to it. Instead, declare it as
Code: [Select]
char str[size]  = "whatever"; and it should run.
Also, always use fgets instead of gets. gets does no boundary check.
« Last Edit: April 12, 2014, 05:34:58 pm by 0poitr »
Imagination is the first step towards Creation.

Offline The Alchemist

  • Peasant
  • *
  • Posts: 100
  • Cookies: 18
  • Cult Of Personality
    • View Profile
    • Scriptings - Paste Tool
Re: [C] Making A Website Blocker With Manifest
« Reply #4 on: April 13, 2014, 12:32:03 pm »
The memory for str is allocated statically off the stack. It's read-only. You can't re-assign a value to it. Instead, declare it as
Code: [Select]
char str[size]  = "whatever"; and it should run.
Also, always use fgets instead of gets. gets does no boundary check.
The value for str is always "127.0.0.1              " I'm not changing it in the code, so I'm using char *str="something" so, whether I do char *str="something" or char str[100] = "something" it wont make a difference.
As far as I know, fgets() is for input from file right(I may be wrong)? I'm using gets() as I'm taking input from keyboard.
Defeat the best... To be the best...

Offline 0poitr

  • Peasant
  • *
  • Posts: 149
  • Cookies: 64
    • View Profile
Re: [C] Making A Website Blocker With Manifest
« Reply #5 on: April 13, 2014, 03:34:58 pm »
Quote
The value for str is always "127.0.0.1              " I'm not changing it in the code, so I'm using char *str="something" so, whether I do char *str="something" or char str[100] = "something" it wont make a difference.
As far as I know, fgets() is for input from file right(I may be wrong)? I'm using gets() as I'm taking input from keyboard.
If you're not going to change *str then why 'd you do this:
Code: [Select]
fputs(str, handler);When you do
*str = "something";
"something" is put into the string table of the executable which is read-only. Trying to write something to a r/o region is going to fail. Allocating it the other way around reserves memory from the stack which is r/w.
Use fgets with the default input stream i.e. stdin.
fgets(site, size, stdin);

Hope this helps.
Imagination is the first step towards Creation.

Offline The Alchemist

  • Peasant
  • *
  • Posts: 100
  • Cookies: 18
  • Cult Of Personality
    • View Profile
    • Scriptings - Paste Tool
Re: [C] Making A Website Blocker With Manifest
« Reply #6 on: April 13, 2014, 07:32:23 pm »
Alright, instead of fputs(str, handler), I'll use fputs("127.0.0.1      ", handler)
That should be even better.
And I'll use fgets too now.
Defeat the best... To be the best...

Offline iTpHo3NiX

  • EZ's Pirate Captain
  • Administrator
  • Titan
  • *
  • Posts: 2920
  • Cookies: 328
    • View Profile
    • EvilZone
Re: [C] Making A Website Blocker With Manifest
« Reply #7 on: April 13, 2014, 09:24:47 pm »
Batch FTW with things like this

Code: [Select]
@echo off
title=EditHosts
setlocal EnableExtensions

set "ExitCode=0"
set "VBS=%Temp%\getadmin.vbs"

:: Check for permissions
>nul 2>&1 "%SystemRoot%\System32\cacls.exe" "%SystemRoot%\System32\config\system"
if "%ErrorLevel%"=="0" goto gotAdmin
if /i "%~1"=="Self" goto ElevateFail
goto UACPrompt

:ElevateFail
set "ExitCode=1"
echo Error: Administrator privileges are required.
pause>nul
goto End

:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%VBS%"
echo UAC.ShellExecute "%~s0", "Self %*", "", "runas", 1 >> "%VBS%"
echo Requesting administrative privileges...
"%VBS%"
goto End

:gotAdmin
shift
if exist "%VBS%" del "%VBS%"
pushd "%CD%"
cd /d "%~dp0"
attrib -r -s "%SystemRoot%\System32\drivers\etc\hosts"
cls
echo Please enter the site you would like to block
set /p site2block=
cls
echo 127.0.0.1 %site2block% >> "%SystemRoot%\System32\drivers\etc\hosts"
attrib +r +s "%SystemRoot%\System32\drivers\etc\hosts"
cls
echo %site2block% has now been blocked, Windows now needs to clear your
echo DNS cache
pause
popd
goto flushdns

:flushdns
ipconfig /flushdns

:End
endlocal & exit /b %ExitCode%

NOTE: I haven't tested the batch file, should work in theory, I had written a batch file that does edit the hosts file before, but I can't find it. This batch file also ensures that you have admin privileges before trying to edit the hosts file

:)

As for your program, you might be having issues with administrator rights, as well as the read only attribute on the hosts file.
[09:27] (+lenoch) iTpHo3NiX can even manipulate me to suck dick
[09:27] (+lenoch) oh no that's voluntary
[09:27] (+lenoch) sorry

Offline 0poitr

  • Peasant
  • *
  • Posts: 149
  • Cookies: 64
    • View Profile
Re: [C] Making A Website Blocker With Manifest
« Reply #8 on: April 14, 2014, 06:50:23 am »
Suit yourself with what you think is necessary or even better. :)



I sense a hint of troll.
Imagination is the first step towards Creation.

Offline ArkPhaze

  • Peasant
  • *
  • Posts: 136
  • Cookies: 20
  • null terminated
    • View Profile
Re: [C] Making A Website Blocker With Manifest
« Reply #9 on: May 06, 2014, 04:29:54 am »
Don't use that shitty MS visual studio crap. I recommend CodeBlocks or C++Builder.

Nothing wrong with MS Visual Studio, especially for Windows development. It's the best IDE out there if developing Windows programs.

Btw... Surprised *nobody* has mentioned that fflush(stdin) has undefined behavior? :S Never use fflush(stdin)...

Read: http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1052863818&id=1043284351

The problem is that I'll bet you that you didn't even know you are probably compiling C code with a C++ compiler. Because with VS it takes a bit of re-work to actually trigger the C compiler to compile your project, rather than the C++ compiler. Try declaring a type (non-void) pointer, and assigning it to the return of a call to malloc() without casting and see what happens.
« Last Edit: May 06, 2014, 04:35:15 am by ArkPhaze »
sig=: ArkPhaze

[ J/ASM/.NET/C/C++ - Software Engineer ]

Offline The Alchemist

  • Peasant
  • *
  • Posts: 100
  • Cookies: 18
  • Cult Of Personality
    • View Profile
    • Scriptings - Paste Tool
Re: [C] Making A Website Blocker With Manifest
« Reply #10 on: June 12, 2014, 09:19:05 am »
Nothing wrong with MS Visual Studio, especially for Windows development. It's the best IDE out there if developing Windows programs.

Btw... Surprised *nobody* has mentioned that fflush(stdin) has undefined behavior? :S Never use fflush(stdin)...

Read: http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1052863818&id=1043284351

The problem is that I'll bet you that you didn't even know you are probably compiling C code with a C++ compiler. Because with VS it takes a bit of re-work to actually trigger the C compiler to compile your project, rather than the C++ compiler. Try declaring a type (non-void) pointer, and assigning it to the return of a call to malloc() without casting and see what happens.
I'm already past this project... Still, I'll try doing it.
Defeat the best... To be the best...