6 Replies - 1761 Views - Last Post: 06 June 2014 - 02:23 PM Rate Topic: -----

#1 Chearcher  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 04-June 14

MD5 Hash to File Name

Posted 06 June 2014 - 01:37 PM

I already know how to obtain the md5 hash of a file, but is there a way to convert the md5 hash back to a file name? If someone could give me some sample code that would be nice to. I cannot find anything by searching the web. Thanks in advance.


-Chear
Is This A Good Question/Topic? 0
  • +

Replies To: MD5 Hash to File Name

#2 Sheepings  Icon User is offline

  • D.I.C Addict

Reputation: 73
  • View blog
  • Posts: 571
  • Joined: 05-December 13

Re: MD5 Hash to File Name

Posted 06 June 2014 - 01:40 PM

What have you tried first?
Was This Post Helpful? 0
  • +
  • -

#3 Ryano121  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1460
  • View blog
  • Posts: 3,286
  • Joined: 30-January 11

Re: MD5 Hash to File Name

Posted 06 June 2014 - 01:47 PM

That goes against the whole point of hashing. A hash function is supposed to be strictly one way - once you generate the hash from the input you shouldn't be able to get back to it (in a perfect world anyways). That being said MD5 is pretty weak and you can get around it these days with the use of rainbow tables and the like. Why do you want to do this?

This post has been edited by Ryano121: 06 June 2014 - 01:49 PM

Was This Post Helpful? 3
  • +
  • -

#4 Chearcher  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 04-June 14

Re: MD5 Hash to File Name

Posted 06 June 2014 - 01:53 PM

View PostRyano121, on 06 June 2014 - 01:47 PM, said:

That goes against the whole point of hashing. That being said MD5 is pretty weak and you can get around it these days with the use of rainbow tables and the like. Why do you want to do this?


This is going to sound odd but - as a learning experience - I am creating a Anti-Virus in VB using MD5 hashes*(obviously it would never be used over professional Anti-Viruses). When you choose the data type of a scan (Drive, Folder, or File) and you pick Folder, you can choose to select a folder. After doing so, the program find the MD5 hash of every file in the folder, then compares to it a database of known virus MD5 Hashes. If one is a match, it is supposed to list the path of the file found. To find the absolute path, I need to know the file's name. There might be an easier way, but I cannot think of one.

* I am aware that programs can easily get around MD5 detection.
Was This Post Helpful? 0
  • +
  • -

#5 Ryano121  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1460
  • View blog
  • Posts: 3,286
  • Joined: 30-January 11

Re: MD5 Hash to File Name

Posted 06 June 2014 - 01:58 PM

In that case you don't even need to reverse the hashing. You should be hashing the actual file anyways and not the filename. This should be taken care of in your folder traversal function. For each file in the folder take the MD5 of the file (you already have the path), if the hash is in the database just add the current path to your results list.
Was This Post Helpful? 1
  • +
  • -

#6 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 12821
  • View blog
  • Posts: 50,612
  • Joined: 12-June 08

Re: MD5 Hash to File Name

Posted 06 June 2014 - 02:01 PM

Ryano's right.. the whole point of one way functions are they are one way.


Quote

After doing so, the program find the MD5 hash of every file in the folder, then compares to it a database of known virus MD5 Hashes.

Why would you not have the folder path you scanned? One would envision your program getting a list of all the files in a folder, right? From there it would hash each one, right? You would know what file you just hashed.. soooo... this problem is not an issue of reversing a one way function but simply keeping your data in structures so you can logical find the start.
Was This Post Helpful? 3
  • +
  • -

#7 Chearcher  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 04-June 14

Re: MD5 Hash to File Name

Posted 06 June 2014 - 02:23 PM

Ok, so I feel stupid right now. Sorry for wasting your time, I was thinking about it harder than I should have been. It now works how I wanted.

Kudos to Ryano and Modi!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1