LinuxQuestions.org
Help answer threads with 0 replies.
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 08-20-2017, 08:17 PM   #1
justmy2cents
Member
 
Registered: May 2017
Location: U.S.
Distribution: Un*x
Posts: 237
Blog Entries: 2

Rep: Reputation: Disabled
Bash Script Troubles


Code:
#!/bin/bash

read -p "Choose a directory you wish to operate in: " var_1
mkdir -p $var_1/Hydra/.Despair0 && cd $var_1/Hydra/.Despair0
    

pwgen -1syN 63 160 | tee lock{1..1000} ### Create 1000 files and fill them with a bunch of text 1000 files so they all are a certain file size
    for i in `ls -1`; do              ### encrypt the 1000 files with random passswords that I do not know
    password2=$(pwgen -1syN 1 10)
    echo "$password2" | gpg --no-use-agent -c --cipher-algo twofish --passphrase "$password2" > $i.gpg
done
shopt -s extglob          
shred -fuz !(*.gpg)              ### delete all files without a gpg extension


    until [ -f $var_3.gpg ]; do
    read -sp "Choose a lock file to contain your secrets (lock1-1000): " var_3 #choosing a file to store my password but first it must be deleted and remade/re encrypted
echo ; done
shred -fuz $var_3.gpg && pwgen -1syN 63 160 > $var_3  ### delete a file from the 1000 files to remake it and specially encrypt it with a custom passphrase
    while true; do                                    ### confirm password
    read -sp "Enter a passphrase to encrypt your secrets: "  passvar_1
    echo;read -sp "Confirm: " passvar_2
    echo;[ "$passvar_1" = "$passvar_2" ] && break
    echo "Please try again"
done

### this is the part whre I specially encrypt the file I deleted and remade
gpg --no-use-agent -c --cipher-algo twofish --passphrase "$passvar_1" $var_3 && shred -fuz $var_3

Last edited by justmy2cents; 08-22-2017 at 12:33 PM.
 
Old 08-20-2017, 08:22 PM   #2
justmy2cents
Member
 
Registered: May 2017
Location: U.S.
Distribution: Un*x
Posts: 237

Original Poster
Blog Entries: 2

Rep: Reputation: Disabled
This is a snippet from a project im working on (im making GnuPG based password manager using Bash).. For some reason the file sizes dont match and im not understanding why. To elaborate, the problem I'm having is this line I think:
Code:
pwgen -1syN 63 160 | tee lock{1..1000} # Filler Text For The Decoy Lock Files In .Despair0
which is supposed to fill random text into the files so they are all a certain file size... This line below creates a file and that file is the file that im comparing to the rest of 999 files, and it for some reason doesn't match them in size. The below line is specifically for filling text into this special file (so it masquerades with their sizes), and as you can see in the script, both lines use pwgen -1syN 63 160, and are both encrypted with the same type of encryption so they should be the same file size.. All I did was delete the file and remake/re-encrypt it, so that I could set a custom passphrase on it (meaning not a randomly generated passphrase like the rest of them)
Code:
shred -fuz $var_3.gpg && pwgen -1syN 63 160 > $var_3
Why does this file (that I will use to store my passwords; which the above line creates, and the very last line encrypts) always ends up with a much larger file-szie than the rest of them...If you try this out yourself, then type ls -l you'll notice that the file the script has you choose (the "special" file aka my password file) ends up with a bigger file size than the rest of them.. If im making it sound complicated I apologize, it's not though it's simply that one file ends is bigger than the rest and im not sure why...

Last edited by justmy2cents; 08-20-2017 at 09:17 PM.
 
Old 08-21-2017, 12:14 AM   #3
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,269
Blog Entries: 24

Rep: Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196
I am not familiar with pwgen, and as it appears to be window$ only I have no way to test it.

That said, it is not at all obvious that it should produce the same size file. The first question I would ask is whether the resulting file is valid - does it work as intended?
 
Old 08-21-2017, 03:43 AM   #4
nigelc
Member
 
Registered: Oct 2004
Location: Sydney, Australia
Distribution: Mageia 7
Posts: 406
Blog Entries: 4

Rep: Reputation: 80
Hi,

Code:
 urpmq -i pwgen
Name        : pwgen
Version     : 2.07
Release     : 2.mga6
Group       : Security
Size        : 42366                        Architecture: x86_64
Source RPM  : pwgen-2.07-2.mga6.src.rpm
URL         : http://sourceforge.net/projects/pwgen/
Summary     : Password generator
Description :
pwgen generates random, meaningless but pronounceable and thus easy to
remember passwords. The also contained makepasswd gives even more
options which are more aimed at security.

[nigel@endor ~]$ pwgen
Ohtei1zo och6Oawo Co6Mangu Iw1paeju Ahseem4r Uuha5epe kooR5xei chieC9Bo
bere1Ohs du9du6Te ieLi1cie haht7ohW eeyai4eW thoh0Iqu eeZ6ohJu ek3Ti3Ou
sohnoYu1 kieb8aiP eiThoh0o Il8meeco teis9Pei fohhi0Th Eix9eisi fe4GeiFi
iiWie2ee MuT7NoWe Tohth1ve aiX4jah5 Uoxai9os Saequ8ai uChikoo7 ooWu7ax2
shahV4cu uuF8beeb eibah7Va gohfeiP3 iQu1ohpo Ooga1lef ohGooc8s Eina4eef
dee2Eyes izir5iPo dahL2oot eeHae0ku poB7Sahz Jaicai5x fo5xa7Ee jievu2Qu
Aevem2va as0Iagee ieWoh9ka aiCha7po Japoh8fa ohn0iKoo axei4Que uaquui5L
aiT4quei gait6moZ caeYo2Si Uo5Aij4s os7Gohh2 aiChe7Oh quai7eiG ohlob8Bu
aiGh0foh eiphaeX6 Eefee5Se Uraith2n ahMaeb9e Fah7Keex Ooghei7u maeRei2s
Si9quugh shu5Lee6 Iecuo9ie Ung6uon7 ahM6keTh Mohngie3 SuZosee0 Xohchai2
iG1yoa5O aGh9que8 Wia5Nohb No0tie5e aiph0Chu quooThu5 ieXoy9ch Riengoh3
Hiel4zee chie0Ahr jee0saeC faecur3M aw5MaiS8 oc9Eidu6 weikoo4W Ya5eeSaN
ohch5aiM Taf2Ohr6 vieY5fee nahThi3R eiNae6oh EeT5choh RaiZih8i iSho1iva
naiXood8 aiKee7Oi loo0haNg Pai9Loo1 gahS9ob5 uGh7eNg3 anah5Dui uarohm1Z
Xiel5iev die4Phoh Aith4die Vahm1noo eiGhoh6v gooGhae2 ue9phiSe pohahz5U
Eiw9yuKu Zohng7sh kooNge2f mu4EMeiB Liy1Thoh yueCuo6d tho2Pauh vi3Uu3ee
aif4Bu2j ahbee5iN Ochee4oh TahK1Kae ohNg1che Wah8Quoo Airumot7 johGh8hu
oi5vie7E rieTai0A Onaa5ohj xeeB0yij ooWoh9se moW3usah bien9Ahw teiC2oon
Ied1AhXa ohng4Bee naeTh8ei nai9tieW uth8ahJo Pahp3eiz su0fohJa shuZ5oos
ieK2wohy fohb4AhL aiG4Xot4 Thook7ai ieng3eSu ahP3Shee Eife1uzi oonooCa2
]

Last edited by nigelc; 08-21-2017 at 03:48 AM. Reason: To add more stuff
 
Old 08-22-2017, 12:27 PM   #5
justmy2cents
Member
 
Registered: May 2017
Location: U.S.
Distribution: Un*x
Posts: 237

Original Poster
Blog Entries: 2

Rep: Reputation: Disabled
Thanks for your responses I found out what was wrong.. I was right I needed to change the line I suspected.. Not sure why, just trail and error.. Mainly I had to change echo "$password2" to echo "$password2:$filler1" Thanks anyways! Btw pwgen is not just for Windows, it works great on Linux, but I believe it was made by Microsoft.. Nevertheless Ill probably remove it as a dependency..

Code:
read -p "Choose a directory you wish to operate in: " var_1
mkdir -p $var_1/Hydra/.Despair0 && cd $var_1/Hydra/.Despair0
    

filler1=$(pwgen -1syN 63 160 | tee lock{1..1000}) ### Create 1000 files and fill them with a bunch of text 1000 files so they all are a certain file size
    for i in `ls -1`; do              ### encrypt the 1000 files with random passswords that I do not know
    password2=$(pwgen -1syN 1 10)
    echo "$password2:$filler1" | gpg --no-use-agent -c --cipher-algo twofish --passphrase "$password2" > $i.gpg
done
shopt -s extglob          
shred -fuz !(*.gpg)              ### delete all files without a gpg extension


    until [ -f $var_3.gpg ]; do
    read -sp "Choose a lock file to contain your secrets (lock1-1000): " var_3 #choosing a file to store my password but first it must be deleted and remade/re encrypted
echo ; done
shred -fuz $var_3.gpg ### delete a file from the 1000 files to remake it and specially encrypt it with a custom passphrase
    while true; do                                    ### confirm password
    read -sp "Enter a passphrase to encrypt your secrets: "  passvar_1
    echo;read -sp "Confirm: " passvar_2
    echo;[ "$passvar_1" = "$passvar_2" ] && break
    echo "Please try again"
done

### this is the part whre I specially encrypt the file I deleted and remade
filler2=$(pwgen -1syN 63 160 > $var_3)
echo "$passvar_1:$filler2" | gpg --no-use-agent -c --cipher-algo twofish --passphrase "$passvar_1" $var_3 && shred -fuz $var_3

Last edited by justmy2cents; 08-22-2017 at 02:02 PM.
 
Old 08-22-2017, 01:16 PM   #6
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,784

Rep: Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083
Quote:
Originally Posted by justmy2cents View Post
Btw pwgen is not just for Windows, it works great on Linux, but I believe it was made by Microsoft
I don't think so, https://raw.githubusercontent.com/ty...bian/copyright says:

Quote:
Upstream-Contact: tytso@mit.edu
Source: https://github.com/tytso/pwgen

Files: *
Copyright: 2001, 2002, 2005, 2006, 2014 Theodore Ts'o <tytso@mit.edu>
License: GPL-2
The author has a wikipedia page: https://en.wikipedia.org/wiki/Theodore_Ts%27o
Quote:
Theodore Yue Tak Ts'o (曹子德) (born 1968) is a software engineer mainly known for his contributions to the Linux kernel, in particular his contributions to file systems. He is the primary developer and maintainer of e2fsprogs, the userspace utilities for the ext2, ext3 and ext4 filesystems, and is a maintainer for the ext4 file system.
 
Old 08-22-2017, 02:12 PM   #7
justmy2cents
Member
 
Registered: May 2017
Location: U.S.
Distribution: Un*x
Posts: 237

Original Poster
Blog Entries: 2

Rep: Reputation: Disabled
Yeah I remember hearing something about pwgen and Windows, I think it was just that it's cross-platform so it can run on both Linux and Windows..

Last edited by justmy2cents; 08-22-2017 at 02:20 PM.
 
Old 08-22-2017, 02:17 PM   #8
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,269
Blog Entries: 24

Rep: Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196
Quote:
Originally Posted by justmy2cents View Post
Btw pwgen is not just for Windows, it works great on Linux
Indeed! My search had led me to this page for PWGen which says...

Quote:
Unobtrusive, fully portable, runs on all 32-bit and 64-bit Windows versions
...and gives every indication in the page that it is pwgen. But I now see in the url it is really pwgen-win, advertising itself as PWGen. Intentionally confusing?

Anyway, glad you got it working!
 
Old 08-22-2017, 02:21 PM   #9
justmy2cents
Member
 
Registered: May 2017
Location: U.S.
Distribution: Un*x
Posts: 237

Original Poster
Blog Entries: 2

Rep: Reputation: Disabled
All good thanks again!
 
  


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
[SOLVED] Bash script troubles amboxer21 Programming 13 10-04-2012 02:46 AM
[SOLVED] Bash troubles amboxer21 Programming 13 08-01-2012 06:33 AM
[SOLVED] troubles with bash script tests "-z" and "-n" SaintDanBert Linux - Software 7 04-10-2012 09:26 AM
SSH connection from BASH script stops further BASH script commands tardis1 Linux - Newbie 3 12-06-2010 08:56 AM
cron bash script troubles zzyzx Slackware 3 04-12-2005 12:27 PM

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

All times are GMT -5. The time now is 12:32 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