Question

In: Computer Science

Overview A cyber-security company called UltraHackz is interested in finding talented computer science students. To do...

Overview

A cyber-security company called UltraHackz is interested in finding talented computer science students. To do so, they post a challenge you find very interesting. They upload a txt file that contains 100 records containing information about 100 system accounts. Each record has a username, a salt value, and a hashed password.

Each record is stored as follows:

<username>,<salt value>,<hashed password>

That is, there is one line per record in the file, where the three values are separated by commas. Your job is to find the real password associated with each of the accounts. They tell you that all passwords contain only numbers (0-9), and that each password is at least 3 characters long, and at most 7 characters long. Your task is to implement a recursive method to generate all possible passwords (brute force). To make it interesting, UltraHackz posted the following rules:

Every time you generate a string s, you need to check if s is the password of any of the usernames in the file. To do so, concatenate s with a user’s salt value, and apply the hashlib.sha256 method to the resulting string. If the output generated by sha256 matches the hashed string for that account, string s is the real account’s password! You accept UltraHackz challenge as you think this is a perfect opportunity to show off your recursion skills!

  • The method MUST be recursive
  • Numbers 3 and 7 are not be hard-coded inside the method that generates the passwords; they should be parameters of the method
  • You can have at most two nested loops inside this method (less than two is perfectly fine as well).

GIVEN CODE

import hashlib

def hash_with_sha256(str):
    hash_object = hashlib.sha256(str.encode('utf-8'))
    hex_dig = hash_object.hexdigest()
    return hex_dig

def main():
    hex_dig = hash_with_sha256('This is how you hash a string with sha256')
    print(hex_dig)

main()

PASSWORD TXT FILE

User0,jjbgis,e0ed8f4991bfbfd73fe604e7d29f77c39185aebe9fab828d4183941de71cf066
User1,sxhizl,4c176c0cad87bd15d5ff2d7b51ca3333fe2b75486523fc4eb00f8838fad7a73c
User2,sktgta,55f1bf027dcf5d8b472300422e21cfece226952c3f81f681ddbc9dd98088f187
User3,aetlli,b463939de2d4bb98df673e2bf7cfc1b2a85630277aec4f3cf3bed46be1f65672
User4,neguch,5372c991ea3b3c9b8eb0e094188d985dba415099687c3d60ca230aedcc3b740b
User5,cmbwgp,bc10a350ec96e61407b3c4035bfb3e724cc90fd63e17c33342a7777d003803e5
User6,djrtxx,8ded6bbf64d75fe508ed0ebfb98fa04076fedb2b9a1b8a6dd8626b5849e64bdc
User7,xnyakp,16243385d71d6499aff8746f9b0859d9bb90231b79a950274f8d8c00de3e64e5
User8,abphyg,e88381b6e7ab945601d5c6ca14bac1171cce68efd37e0eaaa934ed8754f77a65
User9,wwrnfb,70c99f8d3696ba7866cfd30a3f0a8c9697fb042d162be69dc427520fd85ab0ba
User10,acjugd,3d656d1085e879ef1eb24f95a87f87ad0a5400907ca98258bf2012395f5703fe
User11,cxuiuf,8be01c483ad5102969d8ed0ab662d7b4d4c78888d20154b2d024a9b290a50a76
User12,uzavbx,2a9ad244c1c94322a1ac5d4faa0202e69cb10c552770f33a794483283039f0c2
User13,ubonjg,35ecf29e26d9385f6fb1761b2d893b1449d5b69d5b8904f680f92000a3aae74a
User14,dnuvqv,dd31c212068f2e460694dcc5805f2a7fedca5c5e0dff892b5371de37ee201b4b
User15,tmwvbo,aca8d96cd29143fb45ddcb186a9b8d21ce53f58434582d3b58b184e0c56664b2
User16,rzgcar,9da8b2e73dec4e60587a97321a33915bb23b8694fbd44db7168998939665ea22
User17,siiari,53a00e11758bacf172dfba7531ae1f0a6ee977d907fbfe9aec7aa27ec2230834
User18,vvvhib,9b52c47030609d9354b18d78d41b06ebbe5ac4cad2bfdae43dea56547957f286
User19,hbovbc,4419712829f51aa514555e044ae3821108ef50816d871939d122fc03ec9690a4
User20,fwkbbl,01670b4d7fa70a63ff31e88c9f8f178ef216d425a6bf8cc03de0994620b67c55
User21,srdhkv,41bc3fa390da1d3a8cac896958f073fad5bda7fc1f61b64a8395a66509e31aac
User22,vidfjj,2c7d28d1ba9465b7c0fc57c669db4b541b6b9b06e67f0e4da78b285b02de0cd8
User23,utumiu,edec31698783d36251bf2c6c33f8db5ce439a23071cede82059b66c675fc5a3a
User24,akqmfi,65b1f9c5a573ec462ad3333a77c69809129925b721cb872253326550ed881f7e
User25,csndxa,249b418d4ddc0dba39418373a3dff3e5b4e4921374043a74265d7870a17bece0
User26,occvdh,f3c37c35e94d6cf7a39a17a29bdec3316586fd7f6376d2a1f4c67708a7c5354c
User27,thktdx,e7e9d11ee53176d40579ffca93afa2ba14a9f62b6c764d8d2ec130a65f2d91d8
User28,gxsezw,b370b1fb804b6f97de84becdec7eb07d0c05f24d706f946fb0b1b4756f1b5d2a
User29,gtukpf,4f3bda3ece92b77adf102186fb2879d07ce733b8357051c404feaf77742453b6
User30,ylkwyd,998c60302ac7935de9a7d410977beb9c71ccb6464f68cf30daffd88161f6dfdc
User31,mlvotp,39c75f0e0344fbfdc1bc16a56324bb209cf228e87bb8cb835552afbcbf640dfb
User32,ziiuqv,cb69b61ed3de8da6d0c22ef5c67a989c2ca40275956d82f111d39c2634cd3e19
User33,tczsey,c40013da347b25d7e825a30e7880989131053956754a907c2e699397563d41a5
User34,keqrtj,ec06a57a2ffa9ff624243ba08c3d486db325521a813ab998075904e465a6c30e
User35,pyfwtd,0161f38f0f34ce1f8319e41c436e8c4fe74b6492e168eb069bf8087bc969a2d6
User36,lbvqln,da31268ca38e28627f46cdbb9ce7d6e85dd9acf624375bc7a6293068a306c6b7
User37,mpekqk,7d6b805b02468a76c56a35d462ea68fd9c29197d7a47935f3fd133f9e03bde25
User38,mkoqqc,99c707ac43e16f912b38f29fcdfd1291cd616ddb3adea21a877b98c21880866a
User39,etkagc,85a977d2d77d98713541d4660385f893a0663cf1b8ca2773c58390c161409193
User40,avnmal,b91da00bea2665cdb68ae13e04eeb2c2556251b68d200cab94020796cc2e8597
User41,noxyno,e4a4b753bebdad1d91e8ff81d8f14913c53ff7381f3f0c474b04b13984130823
User42,gtlcdq,94eb3e4245e6897fb339dbe52209362312d3a28b09cfc92a8f318268c2e78214
User43,modbof,9851aaa1e41c38654757139b9f65b53d7390df7607fc056e5f79268f7dec031f
User44,hpdrzo,b8067f92fa9774ff07356c1e8f60cc1d27cf1d3b3ddbb93ca02c6ad3ce925e79
User45,kenbqj,12238b39de2f69ae4eef95c0a35d87df776d0424ed9c202c6270bc8998d2e499
User46,qyjpzl,5754d7f3e64b18651fc74bbce2e3ee92e5f0829476ba8a1de690971a333c1c47
User47,iyhsjx,a2cb5bbc440a34ec963ae083e622de2a0b01080222fac6c137f042e04a701ac3
User48,itqbny,d3fc5fd747dd400068c8d2a60eda9dd4e889ab0c8fc80c92fc494635cd89c814
User49,cshyyo,ea8c97f1fede4af7be931ba6914fa508afc1f1b0371edd1ba348947cea1ba9d3
User50,jofhiv,d246552af65b15bb04645f288a75f9a75ed52fee942a305a11397fc62989deae
User51,dqchpu,63d45fddda4f2f3e97ecafbe33ebaac80cf88f63dfde33af6d7e11cdcbe7b267
User52,oiyapb,8d6bd9d382cf7e6687a41e0406e1d0336327b782078cc1063959d8d61c042d77
User53,xeobmu,86a7e48312b5f46eb6963fb151e811b6700732e5a0de4af48b88c649c2538f0c
User54,ekmzmn,e9a553702e9f1090ccd1718da685f0254e3d8e1cda5f3e36351b5c7c0260d2f0
User55,qehzws,4f6dbbf9c314a1eb4115d1af6991a0d573b9492fafe758981d05ce4ca26a18be
User56,wzazff,4491d8b15141b2a751291b7f0276a101d9580fe577e2f37a4769ea9fc441aef6
User57,qkwbhl,0cc09ed481a76c0a155c22a8e0a93e521385b46cba23823396eb9aa10a19c0e4
User58,zmuhnc,f25a34afad2cb2524b700530443b652c81e885ed5a0bfdf8aed5b6e728bcac3c
User59,fpagvz,769f72d1d023f2821d21e9b133c64bec16940c83656b89caacab1aa52d0bde83
User60,mredej,50e1a490d3496bc2be4b85b0ad5f4b275227e2f4ca8c304c705fe3425622354c
User61,czffaq,3d41bc58214710543189c7917cd5f8328f21714641b0b65b7253e270ccd215c3
User62,wdpoyq,e7b6b1e5f6e04e70f98290e5a5a88a4241da88b56eed13a562ad345c668139c2
User63,gcmjls,391fb8cfbde521bdad9637dff2ebbb1938ae4a375461d8c1051fd932b41f25fd
User64,vcgusp,abbb2918c6ff3fc1249c08357dfb602b7b5fb1cdc3b6f618f5d166607beb00c7
User65,ydhjde,5f4918cb399d47bf1c97898b26c2aafe5310af72a423ee8cb4884f1608399ba6
User66,jwzcnd,b02aea7bde75677121105849e711dafbbc7029842e55bdaccf194583a8f2dc01
User67,cxntns,f52190e7fe3fe71ed4a44b06358ad98b3610fff191073dbdfd7e2b6eb75f5805
User68,htqykw,77cc1ab607f65dba7704443a994bd7b93e7f4cfcc9f84b251669b4bebff81ccd
User69,dezzdw,e5666b8c3ef350c9f717fb42dc82cc8f389d782b31591501117c08ce8b813481
User70,xsascm,ce706476b90b8056ad6ae8a08c1819b9983ee6a5905279a16f1b3c469a938005
User71,vuhkrx,50da2c1675cf4761f3258938c4520559fda9b67ceef5ac4e3a5fbb21c7d28cdd
User72,crtvop,a657b9983beec95b7fd4f1c7227fdf64df5f9d5bf2ca1e585d9bb07e8898326c
User73,auoctg,072c15360c3916b930921a7a0d68b1cd701dd4b18cbb4050b59885f812620111
User74,rdolst,3634417ac2033298b63c300f6e1a58b65c5d68418d8665b3395da0df98823fce
User75,ckinbj,4a95134ddb42595acbbc7b870f48a80e1da4d34455a2bb2f5fd2abe81dbc140e
User76,slliho,7c5ceebc0ebfdb530c760d568f797a80764ab6365798a09875d2784bd8048407
User77,ffedej,ecfbc5f89e592a30f6925b108cff0e82e1079d4bfd54d8d371657da25e0c5702
User78,nhtrxt,20efa3f2aaaf0a6e9641d696dcd137b4e398d5a5e84eb43af6272c3c051fcfd6
User79,gqrczq,d3d050a8545fc053646f2c8f01879df5280e15f5f47a13cc871284eafca23a1e
User80,ddbayp,f54212ef20f02678d96afcb34cf1283078fd7220a928b731aa8a8b3546897c6d
User81,bdruse,83bb7f63490c2cbc43218225049280040d3ed1e093f2eb6d459728620f6f2b72
User82,pkojrj,988d487f9f978ba2566ee428ded195a2e3453c44869766cad9440ae9da286b00
User83,ojxstn,ed0bbb5049bc4ce91d773ee5f46d2b27f2a57c96d60ee5ee81fe67774c3eabd8
User84,axjznb,8060ea24c656ef002edc6b4ffad801f1d949b9d7c0e9b96981f6652e49387d7f
User85,qrsbet,fcf7187a25652b0bda4c2f0b88b2b60b1e5106b1e97f6bc2d0e4b53377e5f965
User86,iwhmqd,b78ded8f140ba458e31ae5f3d1a7b40316b3822598c23bac8374acaa3e8a44e7
User87,qvyfkm,0bb7e06350b676bc5c29539ba71568ce8d1e0d884329d5493d6813bfd8a4b3bc
User88,zuonmr,d9c142abfcc52d81262c9a38f0b793c33cd5e5529bfe4917eeabcc395da9b51e
User89,venhve,228313a26a81b99b8cf1f18bd205e6ae7e9024c44abae3314d533527379a54f4
User90,lsmnka,d339bdcb28af07547c470577eab4744f58a46462eddea2d46c96f3d3f3d54c59
User91,hefcoq,05023efa6f72285a2253775858d7cd27be9490f0679b5a8e46f20627725c11eb
User92,phtqrn,7d89a025429f336fddadc929c4c42b636d706382a411c56b6d53afbf4005d89f
User93,kypjov,6c3af69bc50ccd1e7562fc10a7607d84cbdb331ad987b83cef2fc0b73afd9cb8
User94,jjalch,c37882eb81ead948b2e30c01ceca18bf92c3c1c2090d3f321cea7b641f26167d
User95,jqejia,b49eb4ff02053d8b8ab54378053d90515f4b47858512f35553141edcb9849559
User96,xwfacd,daa28076b7e843d64127fca6b6f9fee5158af9124f09219e13f237e6ffa733c0
User97,rvnoao,2ac75e1384006eba400c892d1994a00b8205d66d8764d32d48258576a5e0b473
User98,fhfulw,da0547e9568d457e5c9e140a0af38c24685c5b237dd3b41afad010269375f728
User99,flncco,5a509ef5141de91f106816f00a81765de2be54d7d7b1ae37fb6d1f9c3daee98c

Solutions

Expert Solution

import hashlib
import itertools
def hash_with_sha256(str):
hash_object = hashlib.sha256(str.encode('utf-8'))
hex_d = hash_object.hexdigest()
return hex_d
def main():
x = input("Enter min password length:")
y = input("Enter max password length:")
lis = []
for j in range(int(x), int(y)+1):
for i in itertools.product([0,1,2,3,4,5,6,7,8,9]):
repeat = int(j)
lis.append(",".join(map(str,i)))
print("Password Generated")
input_f=open("user_data.txt","r")
for line in input_f:
name,salt,hashed_value = line.split(",")
salt.replace("","")
hashed_value.replace(" ","")
print("BruteForce Attack")
for password in lis:
password.replace("","")
hex_d=hash_with_sha256(salt+password)
if(hex_d == hashed_value):
print(user+"has password"+password)
break
main()
  

Screenshot code:

output:


Related Solutions

The head of a computer science department is interested in estimating the proportion of students entering...
The head of a computer science department is interested in estimating the proportion of students entering the department who will choose the new computer engineering option. A preliminary sample indicates that the proportion will be around 0.208. What size sample should the department head take if she wants to be 95% confident that the estimate is within 0.02 of the true proportion?   
A political science professor is interested in comparing students who do and do not vote in...
A political science professor is interested in comparing students who do and do not vote in federal elections. She computes the mean grade point average for a random sample of 14 students who have voted in the last federal election to be 2.51 with a standard deviation of 0.44. She computes the mean grade point average for a random sample of 15 students who did not vote in the last election to be 2.98 with a standard deviation of 0.56....
a) Examine the three elements of Cyber Security that are generally used to protect computer networks and systems.
a) Examine the three elements of Cyber Security that are generally used to protect computer networks and systems.  b) An ethical dilemma is a situation a person faces in which a decision must be made about appropriate behavior. Discuss any five key professional ethical values to be considered when faced with ethical dilemma at the work place. c) Jeremy Bentham (1748-1832) once said “The greatest goal is to achieve the greatest happiness for as many people as possible.” Clearly explain what he...
Regarding the book"ESSENTIAL CYBER SECURITY SCIENCE by JOSIAH DYKSTRA, Chapter 4 & Chapter 5 ., especially...
Regarding the book"ESSENTIAL CYBER SECURITY SCIENCE by JOSIAH DYKSTRA, Chapter 4 & Chapter 5 ., especially CHapter 4 & Ch-5 ONLY... Will you please describe in detail the hardware and software used in those chapter (4&5 only)? Thanks
You are one of the top students in your university’s computer science program of 200 students....
You are one of the top students in your university’s computer science program of 200 students. You are surprised when you are met after class by two representatives from a federal intelligence agency. Over dinner, they talk to you about the increasing threat of cyberterrorist attacks launched on the United States by foreign countries and the need to counter those attacks. They offer you a position on the agency’s supersecret cyber terrorism unit, at a starting salary 50 percent higher...
1.Do you think cyber insurance is necessary? If a company has strong enough security policies and...
1.Do you think cyber insurance is necessary? If a company has strong enough security policies and technology-based protection, does it need cyber insurance? 2. What types of events (risks) do you think a cyber insurance policy should cover? 3. If you were an underwriter for a cyber insurance policy, and your job is to evaluate a company's security risks, what are some of the things you would look at and look for, both positive and negative.
A researcher is interested in finding a 95% confidence interval for the mean number minutes students...
A researcher is interested in finding a 95% confidence interval for the mean number minutes students are concentrating on their professor during a one hour statistics lecture. The study included 41 students who averaged 34.7 minutes concentrating on their professor during the hour lecture. The standard deviation was 12.1 minutes. Round answers to 3 decimal places where possible. a. To compute the confidence interval use a distribution. b. With 95% confidence the population mean minutes of concentration is between and...
A researcher is interested in finding a 90% confidence interval for the mean number minutes students...
A researcher is interested in finding a 90% confidence interval for the mean number minutes students are concentrating on their professor during a one hour statistics lecture. The study included 128 students who averaged 42.3 minutes concentrating on their professor during the hour lecture. The standard deviation was 10.7 minutes. Round answers to 3 decimal places where possible. a. To compute the confidence interval use a _____ (t? or z?) distribution. b. With 90% confidence the population mean minutes of...
A researcher is interested in finding a 95% confidence interval for the mean number minutes students...
A researcher is interested in finding a 95% confidence interval for the mean number minutes students are concentrating on their professor during a one hour statistics lecture. The study included 133 students who averaged 41.3 minutes concentrating on their professor during the hour lecture. The standard deviation was 13.3 minutes. Round answers to 3 decimal places where possible. a. To compute the confidence interval use a ? t z  distribution. b. With 95% confidence the population mean minutes of concentration is...
A researcher is interested in finding a 99% confidence interval for the mean number minutes students...
A researcher is interested in finding a 99% confidence interval for the mean number minutes students are concentrating on their professor during a one hour statistics lecture. The study included 105 students who averaged 38.1 minutes concentrating on their professor during the hour lecture. The standard deviation was 11.2 minutes. Round answers to 3 decimal places where possible. a. To compute the confidence interval use a ? z t  distribution. b. With 99% confidence the population mean minutes of concentration is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT