LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Access sectors of HDD in C++ (https://www.linuxquestions.org/questions/programming-9/access-sectors-of-hdd-in-c-547357/)

vargadanis 04-19-2007 12:04 PM

Access sectors of HDD in C++
 
Hi,

I am trying to create an app that would access the MBR of the HDD. I know that this is located in the first sector of the HDD but I don't know how to access it. Is there a way to access the HDD in C++ or C with which I could access sectors and it's contents not files?
Eg: MFT is in the MBR on NTFS parts and I would love to read this file. (^_^)

Matir 04-19-2007 12:11 PM

Are you trying to do this under *NIX or Windows? If NIX, you can fopen the device just like any other file. e.g,
Code:

fopen("/dev/hda1","r");

vargadanis 04-19-2007 07:05 PM

Windows... I want to access the SAM file from a limited account and read it's contents. I need an executable that accesses the HDD as it is and uses the MFT to determine where exactly it is. After that just read it out. No hacking or such but I want to see if it was possible to do it.
From linux I would just mount it and copy the SAM file or modify it's rights or attributes and problem would be solved, however there are cases when you can't just boot up a linux.

suicideducky 04-19-2007 11:25 PM

Quote:

Originally Posted by vargadanis
Windows... I want to access the SAM file from a limited account and read it's contents. I need an executable that accesses the HDD as it is and uses the MFT to determine where exactly it is. After that just read it out. No hacking or such but I want to see if it was possible to do it.
From linux I would just mount it and copy the SAM file or modify it's rights or attributes and problem would be solved, however there are cases when you can't just boot up a linux.

ohh you mean cases like in a virus!
just kidding,
I havent done any C++ coding for quite some time, So sorry but I can't help you there :scratch:

and if you are hacking then you can use ntpasswordrecovery to overwrite the same file,
and ntpassword recovery also allows you to copy the sam file before overwriting it.

But you can copy it nontheless, is this the kind of function you want?
or would you rather impliment it in your own code? :p

suicideducky 04-19-2007 11:29 PM

Quote:

Originally Posted by vargadanis
Windows... I want to access the SAM file from a limited account and read it's contents. I need an executable that accesses the HDD as it is and uses the MFT to determine where exactly it is. After that just read it out. No hacking or such but I want to see if it was possible to do it.
From linux I would just mount it and copy the SAM file or modify it's rights or attributes and problem would be solved, however there are cases when you can't just boot up a linux.

Ok well I remembered the command and did a google on it and heres the command

// basic file operations
#include <iostream>
#include <fstream>
using namespace std;

int main () {
ofstream myfile;
myfile.open ("example.txt");
myfile << "Writing this to a file.\n";
myfile.close();
return 0;
}

Is that what you want?
I remembered Myfile simply because I used it to write to log files late last year at school :D

Ducky.

vargadanis 04-20-2007 10:22 AM

Ahm... Not exactly. With this you are using the kernel and the NTFS partition to access the files. If you do not have the permissions to do so, you are screwed. Therefore this is not really a functioning solution.

Maybe, what I will do is to grab a runnable linux distro, run it under windows and just hack the file.
I have no intention to write a virus for Windows. This would be only for recovery purposes for my Mom. She always forgets her passwd. (^_^)

Matir 04-20-2007 04:31 PM

The Windows kernel won't allow you to directly access the hard drive (i.e., bypass the filesystem layer). It's intended as a security mechanism to prevent exactly what you are trying to do. :)

dmail 04-20-2007 04:40 PM

Quote:

I have no intention to write a virus for Windows. This would be only for recovery purposes for my Mom. She always forgets her passwd.
This may well be your reasoning, but sorry I just don't believe it. For your information the sam file is encrypted so of what use would it be? There are tools and methods all over the net, but I would be very surprised if anybody here posted the methods required. If your reasoning is genuine, create an admin account on your mothers machine, so that you can reset her password.

vargadanis 04-20-2007 06:59 PM

Quote:

I just don't believe it.
Come on, man! Why don't you believe it? I don't even understand. ;)

I didn't know that the kernel can prevent me from doing anything. How is it working? Is there a feature like this under linux too? Most likely but I don't know about it.

Dani

dmail 04-20-2007 07:27 PM

Doesn't the following say it all?
Quote:

For your information the sam file is encrypted so of what use would it be?
Hell I know windows is slack on security, but surely you don't think you can just read the password straight out of the file and use it?

Do I have to believe you?
There are easy ways of doing this google is your friend, yet 99.999999999999999% of the time its used to gain illegal access to an account. :)

Matir 04-20-2007 08:29 PM

Under linux, you can read devices directly, but only as a trusted user. A normal account would not allow you to read it from the disk under Linux.

vargadanis 04-20-2007 09:15 PM

Nope... I knew that the file is encrypted but it can be decrypted too. :) There must be some kind of method to do so.

Dmail... You don't nee to believe me. However I am always supposing of other ppl - at least for the first time - that they are saying the truth. In this case I was sarcastic and you were right that you didn't believe me.

Why don't we close the off?

dmail 04-21-2007 04:33 AM

Quote:

However I am always supposing of other ppl - at least for the first time - that they are saying the truth.
Personally I question everything of people I do not know and this just had alarm bells going off. Read the quotes yourself and see the inconsistencies in them.

Quote:

I am trying to create an app ...I would love to read this file....want to access the SAM file from a limited account...No hacking or such but I want to see if it was possible to do it....however there are cases when you can't just boot up a linux....run it under windows and just hack the file....This would be only for recovery purposes for my Mom. She always forgets her passwd
Quote:

There must be some kind of method to do so.
Sure there is but I am not going to help you and supply the answer, that would be just irresponsible and would probably get me banned.

vargadanis 04-21-2007 05:47 PM

Doh... As you feel. I didn't expect to get an answer for such question anyway. Or at least I hoped so. I hoped that ppl would say that hey, are you trying to write something that could affect MS Windows users badly? I am sorry, but my moral is too high to help to you.
Inconsistency might have occurred as I didn't really want to let the people know that I want to trick out the system and gain access to information to which I am not supposed to. No matter if it is the SAM file or just the My Documents. The is what police is building on when they are questioning the accused many times and they are looking for inconsistency.
But also I must let you guys all know (either you believe me or not) that I had no intention to harm other people. I am writing such application just to see if I am capable or not. I am just trying to figure out ways that are not that simple, ways that could save my butt some day at work or ways that my boss will be impressed with. I am just learning.

Matir 04-21-2007 07:58 PM

Learning is good. We do encourage learning. Unfortunately, too many people claim to be 'learning' with malicious intent... it's hard for us to find the line, so we have to limit it entirely.


All times are GMT -5. The time now is 03:19 AM.