LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-19-2007, 12:04 PM   #1
vargadanis
Member
 
Registered: Sep 2006
Posts: 248

Rep: Reputation: 30
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. (^_^)
 
Old 04-19-2007, 12:11 PM   #2
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
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");
 
Old 04-19-2007, 07:05 PM   #3
vargadanis
Member
 
Registered: Sep 2006
Posts: 248

Original Poster
Rep: Reputation: 30
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.
 
Old 04-19-2007, 11:25 PM   #4
suicideducky
Member
 
Registered: Aug 2006
Location: New Zealand
Distribution: Gentoo
Posts: 72

Rep: Reputation: 15
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

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?
 
Old 04-19-2007, 11:29 PM   #5
suicideducky
Member
 
Registered: Aug 2006
Location: New Zealand
Distribution: Gentoo
Posts: 72

Rep: Reputation: 15
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

Ducky.
 
Old 04-20-2007, 10:22 AM   #6
vargadanis
Member
 
Registered: Sep 2006
Posts: 248

Original Poster
Rep: Reputation: 30
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. (^_^)
 
Old 04-20-2007, 04:31 PM   #7
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
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.
 
Old 04-20-2007, 04:40 PM   #8
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
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.
 
Old 04-20-2007, 06:59 PM   #9
vargadanis
Member
 
Registered: Sep 2006
Posts: 248

Original Poster
Rep: Reputation: 30
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
 
Old 04-20-2007, 07:27 PM   #10
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
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.

Last edited by dmail; 04-20-2007 at 07:33 PM.
 
Old 04-20-2007, 08:29 PM   #11
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
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.
 
Old 04-20-2007, 09:15 PM   #12
vargadanis
Member
 
Registered: Sep 2006
Posts: 248

Original Poster
Rep: Reputation: 30
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?
 
Old 04-21-2007, 04:33 AM   #13
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
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.
 
Old 04-21-2007, 05:47 PM   #14
vargadanis
Member
 
Registered: Sep 2006
Posts: 248

Original Poster
Rep: Reputation: 30
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.
 
Old 04-21-2007, 07:58 PM   #15
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
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.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
What r the functions used to read data from the all the sectors of hdd nutanj Programming 2 10-30-2006 11:03 AM
Bad sectors in RAID 5 HDD arunabh_biswas Linux - Software 2 06-16-2006 12:25 PM
How to access a PCMCIA HDD cwwilson721 Slackware 3 01-29-2006 03:30 PM
Multiple access to the same HDD F0ul_Olli Linux - Hardware 3 09-07-2005 11:15 AM
How to access raw sectors on HDD with no file system? prasanthpooyath Programming 4 01-08-2005 10:53 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration