Generate random numbers in script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Generate random numbers in script
# 8  
Old 03-17-2013
Quote:
Originally Posted by alister
It's possible, but as Corona pointed out, it's not at all secure. The best that you can hope for is to deter a lazy and incompetent adversary, someone who doesn't want to think through the code and who doesn't know enough to enable tracing (set -x) on your script.

You can't even do this in C or assembly language. If the instructions are there, they can be decoded.

It would probably be much more constructive if you described what you're defending against.
Regards,
Alister
thank you. to mr. corona, i apologize if my post was offensive. my intent was to merely point out that i've been through enough impossible situations to know things can be possible if only thought of in a slightly different way. that's all.

and mr. alister, thank you for your insight. much appreciated!
# 9  
Old 03-17-2013
How can you produce a random number and then know it, even as the script witer?
Anyhow - you may consider a different approach: Use a pass phrase that only you know and compute its checksum; use that as your number.
# 10  
Old 03-17-2013
Quote:
Originally Posted by SkySmart
my intent was to merely point out that i've been through enough impossible situations to know things can be possible if only thought of in a slightly different way. that's all.
There are ways that would work, but you haven't wanted them. You're doing the opposite of what you think, clinging to one notion, not being creative.

Running them on a system you control and they don't; that would keep it safe.

Denying them access to the file, only allowing it to be run through sudo. That would keep it safe from anything but root.

Encrypting it with a ssl key, so it could only be run with a password, that would keep it safe from anyone that didn't know the password. (But not from anyone that did.) Note that they don't necessarily have to be the ones to punch in the password; you could type the password into ssh-agent, to keep it around for multiple later uses. Or the program could keep itself resident after being run once. Still difficult to perfectly protect from root but conceptually a lot harder to break.

Some sort of hardware-based crypto where the processor itself doesn't have access to the program, would also work.

But having a program containing its own instructions and key for decrypting itself into plaintext running itself on an 'enemy' machine cannot be made secure.

Last edited by Corona688; 03-17-2013 at 07:22 PM..
This User Gave Thanks to Corona688 For This Post:
# 11  
Old 03-17-2013
Quote:
Originally Posted by RudiC
How can you produce a random number and then know it, even as the script witer?
Anyhow - you may consider a different approach: Use a pass phrase that only you know and compute its checksum; use that as your number.
this could work! thank you!

---------- Post updated at 06:24 PM ---------- Previous update was at 06:19 PM ----------

Quote:
Originally Posted by Corona688
There are ways that would work, but you haven't wanted them. You're doing the opposite of what you think, clinging to one notion, not being creative.

Running them on a system you control and they don't; that would keep it safe.

Denying them access to the file, only allowing it to be run through sudo. That would keep it safe from anything but root.

Encrypting it with a ssl key, so it could only be run with a password, that would keep it safe from anyone that didn't know the password. (But not from anyone that did.) Note that they don't necessarily have to be the ones to punch in the password; you could type the password into ssh-agent, to keep it around for multiple later uses.

Some sort of hardware-based crypto where the processor itself doesn't have access to the program, would also work.

But having a program containing its own instructions and key for decrypting itself into plaintext running itself on an 'enemy' machine cannot be made secure.
thank you very much. when i asked the question, i was only going off my limited knowledge on this. and i'm very open to any ideas, as you put forth, that may be available.

the people who will be running the code will mostly have root access. so that kinda limits the options of things i can do. i'm very curios about what you said here:

"Some sort of hardware-based crypto where the processor itself doesn't have access to the program, would also work."

i will look into that. thanks again!!!
# 12  
Old 03-17-2013
Quote:
Originally Posted by SkySmart
"Some sort of hardware-based crypto where the processor itself doesn't have access to the program, would also work."

i will look into that. thanks again!!!
Basically means installing a gadget in their computer to run the program instead of running it natively. A black box they can't dissect -- unlike code running on their machine, which they can dissect at their leisure. Probably not what you had in mind.

Perhaps insulating it inside a virtual machine instead of a physical one, as well.
# 13  
Old 03-17-2013
Quote:
Originally Posted by SkySmart
if this is possible, i would be elated.
And what's to stop them from watching the script as it extracts this obfuscated number from itself? You can't stop root from being root.
# 14  
Old 03-17-2013
If all you want is a random number for use in a shell script, both ksh and bash will give you a "random" number whenever you expand $RANDOM.

But, as has already been stated several times, trying to obfuscate a shell script by encrypting it and decrypting it when it is executed won't fool anyone who is willing to spend a little time to figure out how it works.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to generate sequence of numbers

I need awk script to generate part number sequencing based on data in multiple columns like below Input File --------- Col A|Col B|Col C| 1|a|x| 2|b|y| |c|z| | |m| | |n| And out put should be like 1ax 1ay 1az 1am 1an 1bx 1by (6 Replies)
Discussion started by: aramacha
6 Replies

2. UNIX for Advanced & Expert Users

UNIX script for making random numbers without repetition

Hello, I have a column which have 7200 numbers and I am deciding to pick up 1440 numbers randomly without any reputation? Could any one let me know which script in unix will be work for my case? Regards Sajjad (17 Replies)
Discussion started by: sajmar
17 Replies

3. Shell Programming and Scripting

Need to generate a file with random data. /dev/[u]random doesn't exist.

Need to use dd to generate a large file from a sample file of random data. This is because I don't have /dev/urandom. I create a named pipe then: dd if=mynamed.fifo do=myfile.fifo bs=1024 count=1024 but when I cat a file to the fifo that's 1024 random bytes: cat randomfile.txt >... (7 Replies)
Discussion started by: Devyn
7 Replies

4. Shell Programming and Scripting

Generate 16 digit positive random Numbers

Hi Unix Gurus, I have a requirement to generate positive random 16 and 13 digit numbers. Here is the script I have so far..... number=$RANDOM$RANDOM$RANDOM$RANDOM; let "number %= 10000000000000"; echo $number But sometimes it is generating negative numbers and also 15 digit... (8 Replies)
Discussion started by: scorpioraghu
8 Replies

5. Programming

generate array of random numbers

hi guys, I am writing a c program that generates a two dimensional array to make matrix and a vector of random numbers and perform multiplication. I can't figure out whats wrong with my code. It generates a matrix of random numbers but all the numbers in the vector array is same and so is the... (2 Replies)
Discussion started by: saboture88
2 Replies

6. Programming

Generate random number

I saw this formula to generate random number between two specified values in shell script.the following. $(((RANDOM%(max-min+divisibleBy))/divisibleBy*divisibleBy+min)) Give a example in book. Generate random number between 6 and 30.like this. $(((RANDOM%30/3+1)*3)) But I have a... (1 Reply)
Discussion started by: luoluo
1 Replies

7. Shell Programming and Scripting

shell script to auto process ten random files and generate logs

Hello member's I'm learning to script in the ksh environment on a Solaris Box. I have 10 files in a directory that I need to pass, as input to a batch job one by one. lets say, the files are named as follows: abcd.txt ; efgh.bat ; wxyz.temp etc. (random filenames with varied extensions ).... (1 Reply)
Discussion started by: novice82
1 Replies

8. Shell Programming and Scripting

how do i generate random integer using only shell script

Hi All, I need to generate 4 digit random no using only shell script. Please help in this ASAP. Thanks in advance... Regards, sridhar. (1 Reply)
Discussion started by: sridhusha
1 Replies

9. Shell Programming and Scripting

Generate a random password

Hello All... Can someone help me generate a random password which will be 7 characters long which contains alpha-numeric characters using shell script. I am looking to store the output of the script that generates the password to a variable within a script and use it as the password. ... (5 Replies)
Discussion started by: chiru_h
5 Replies

10. Programming

How to generate a random number?

How to generate a random integer with specific range(for example, from 1 to 1000)? Also, how to convert a floating point number into a integer? (2 Replies)
Discussion started by: MacMonster
2 Replies
Login or Register to Ask a Question