bash script for password recovery


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting bash script for password recovery
# 1  
Old 01-06-2011
bash script for password recovery

Hi all,

I'm a complete newbie to bash scripting, although I have some experience in programming. The thing is that I have a .dmg file on my mac which I protected with a password, and now I've forgotten it.

I remember the first few letters of the password and the characters that represent the last few letters, so I want to write a script that goes through all the options iteratively to find the correct one

Code:
#!/bin/bash
#my array of password options
psswrd=( one two three )
#first call to open the dmg file
hdiutil attach DOCS.dmg
#here i give it a wrong input password on purpose so it enters the loop
while [ $? = 1 ]; do
	hdiutil attach DOCS.dmg
        #at this point I'm prompted with "Enter password to access "DOCS.dmg":"
        #and instead of typing the input I want to iterate through the array "psswrd" and use each of its elements in turn as an answer to the prompt
        #also i want to be able to exit the loop if i've gone through the entire array and not found the correct password
done


Any help would be deeply appreciated.

Cheers.
# 2  
Old 01-06-2011
Code:
for let5 in a b c d e f g h i j k l m n o p q r s t u v w x y z
do
for let6 in a b c d e f g h i j k l m n o p q r s t u v w x y z
do
for let7 in a b c d e f g h i j k l m n o p q r s t u v w x y z
do
 try_pw=$let14$let5$let6$let7
 . . .
done
done
done

# 3  
Old 01-06-2011
Quote:
Originally Posted by DGPickett
Code:
for let5 in a b c d e f g h i j k l m n o p q r s t u v w x y z
do
for let6 in a b c d e f g h i j k l m n o p q r s t u v w x y z
do
for let7 in a b c d e f g h i j k l m n o p q r s t u v w x y z
do
 try_pw=$let14$let5$let6$let7
 . . .
done
done
done

Code:
for let5 in {a..z}
do
for let6 in {a..z}
do
for let7 in {a..z}
do
 try_pw=$let14$let5$let6$let7
 . . .
done
done
done

# 4  
Old 01-06-2011
try echoing the password into it with a pipe.

Code:
if echo password | htiutil
then
        echo password worked
        break;
fi

if it won't take passwords that way, you may need to use the expect utility to fake having a virtual terminal.
# 5  
Old 01-07-2011
Yes, it it reads password using /dev/tty not stdin you need a pseudo terminal. Tools like expect might be slower and more trouble than somethng like this, the poor man's expect:
Code:
 
(
  Insert code to generate passwords and from them generate "a script to try passwords on the remote bash",
   checking output_file for failure before generating and trying the next password,
   and exiting printing the last password on success.  N Failures might be easier to determine than success. 
  Some authenticators faill all passwords after the first three tries, so you need a fresh session to ensure your results are real.
 )|ssh2 localhost bash >output_file 2>&1

I am a ksh guy, and usually do not have ..:
Code:
$ for i in {a..z}
> do
> echo $i
> done
{a..z}
$

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Make a password protected bash script resist/refuse “bash -x” when the password is given

I want to give my long scripts to customer. The customer must not be able to read the scripts even if he has the password. The following command locks and unlocks the script but the set +x is simply ignored. The code: read -p 'Script: ' S && C=$S.crypt H='eval "$((dd if=$0 bs=1 skip=//|gpg... (7 Replies)
Discussion started by: frad
7 Replies

2. Homework & Coursework Questions

Password recovery in login script help

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Hi guys. My case study is about creating a script that includes password recovery whenever a user forgets... (1 Reply)
Discussion started by: jenimesh19
1 Replies

3. Cybersecurity

Password Recovery

Perderabo has made posted a good thread in the FAQ section here: Lost root password / Can't login as root | Unix Linux Forums | Answers to Frequently Asked Questions (6 Replies)
Discussion started by: norsk hedensk
6 Replies

4. Cybersecurity

password recovery

I am trying to access an old email account but cannot recall the password and the backup email account has been closed, also. I need instructions or an expert who can assist recovering my password for web-based email account. (4 Replies)
Discussion started by: pp_mcgee
4 Replies

5. Solaris

OpenBoot Firmware Password Recovery

So in the group of boxes I've inherited, I have one that has a firmware password. I do not know the root password of the machine nor the firmware password. I've tried several things already, such as: removing BIOS battery, double tap the power switch, and several variants of the STOP-A on a PC... (2 Replies)
Discussion started by: adelsin
2 Replies

6. Forum Support Area for Unregistered Users & Account Problems

password recovery

hello, my password got lost - and your service to generate new passwords does not work -ive tried it out 50 times the last week or so, never got a single mail from it... please generate a new password for my account "congo" with mailadress. thanks. Thomas (3 Replies)
Discussion started by: congo00000001
3 Replies

7. UNIX for Dummies Questions & Answers

Password Recovery

Hi, I am new to unix and I set a password for a user and now I need to recover what that password was. Is there a way, where as root, I can view what a users passwords is? Thanks, Eric (2 Replies)
Discussion started by: ejbrever
2 Replies

8. Shell Programming and Scripting

help for db password recovery

hi,all my database (.db) is created by sysbase adaptive server anywhere7.0 ! the user id is DBA. but I lost the password . Could you recovery the passwrod of this db file? thanks ! iwind (1 Reply)
Discussion started by: northwind
1 Replies

9. UNIX for Dummies Questions & Answers

Password recovery

We recently terminated a developer at my place of employment who created scripts on a windows server (that i do not have access to) that invoke FTP sessions on my UnixWare 7.1.1 servers. I need to know the password that is being used. Does anyone know of a good password crack? (8 Replies)
Discussion started by: rm -r *
8 Replies

10. UNIX for Dummies Questions & Answers

How to password recovery on Ultrix

I got myself a dec 5100 running ultrix with unknow password, how do i recover or change the root password on it? (10 Replies)
Discussion started by: cybermike
10 Replies
Login or Register to Ask a Question