Help using variable in find rule


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help using variable in find rule
# 8  
Old 10-02-2012
Quote:
Originally Posted by Corona688
Because the command is being run from a variable. I'm guessing he didn't do that on a lark, but because he wanted the contents to vary depending on how the script is used.

That leaves room for injection of malicious strings unless done very, very carefully.

It's also completely avoidable by just not using eval at all.
Let's try to be mor specific. It's interesting, I'm curious about it. Smilie

The only way I'm able to think of is that of a parameter automatically built reading things (maliciously writable by others). For example, let's say I want to discard all files having the same extension of the files in the current directory.

Code:
lem@biggy:/tmp/dir$ ls -a1
.
..
a.txt
b.sh
c.pdf
malicious.; ls ~

Code:
lem@biggy:/tmp/dir$ for a in *.* ; do arr+=( "-not -name \*.${a##*.}" ) ; done

Code:
lem@biggy:/tmp/dir$ echo ${arr[@]}
-not -name \*.txt -not -name \*.sh -not -name \*.pdf -not -name \*.; ls ~

Code:
lem@biggy:/tmp/dir$ eval find /path ${arr[@]}
 ... funny output with ls, disaster with rm ...

So is this what you're fearing? Are there other noticeable and completely different dangers? Thanks. Smilie
--
Bye
# 9  
Old 10-02-2012
Quote:
Originally Posted by Lem
Let's try to be mor specific. It's interesting, I'm curious about it. Smilie

The only way I'm able to think of is that of a parameter automatically built reading things (maliciously writable by others).
How about a file named `rm -Rf ~/` ? That's a perfectly valid filename. Feed that filename into an eval and it will be executed.

If you quote it defensively, so what? They can put quotes and spaces in the filename to unquote it.

It needn't even be malicious. People can generate weird filenames by accident sometimes, and anything resembling shell syntax is something eval will try to parse, potentially causing syntax errors or worse. Eval can parse any shell syntax, so the only limit is your imagination.

And it's completely avoidable. Eval is not needed here.

Last edited by Corona688; 10-02-2012 at 06:34 PM..
# 10  
Old 10-09-2012
I changed my code as follows

Code:
#!/bin/ksh

set -- "-not" "-name" "*.xom" "-a" "-not" "-name" "*.sh" "-a" "-not" "-name" "*.pl"

/usr/local/bin/find path/to/files $@ > FileList.txt

It is working beautifully and it sounds like it will be much safer to run. Thanks for your help.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to find no of underscores in a variable?

Hi i have a variable var=a_b_c i want command to find no. of underscores in a variable Thank you (7 Replies)
Discussion started by: pracheth
7 Replies

2. Shell Programming and Scripting

Find string in variable

korn shell, testing if a pattern exist in a string, x is constant, y could be none,all or any combination of the elements of x, x="aa bb cc dd ee ff gg hh ii jj kk ll" y="ff kk" for z in `echo ${x}` do if <any pattern in $y matches any pattern in $x> ] then do something fi... (3 Replies)
Discussion started by: squrcles
3 Replies

3. Solaris

Jumpstart -- Warning: Could not find matching rule in rules.ok

I just setup a new jumpstart server, and I'm having problems with rules.ok errors. I'm coming up blank after many Google searches, forum searches, etc..... This is the error I receive: Skipped interface e1000g1 Attempting to configure interface e1000g0... Configured interface e1000g0... (0 Replies)
Discussion started by: christr
0 Replies

4. IP Networking

iptables - most easy way to find rule and remove it?

I have situation where I have rules in iptables with comments. Now... I can for example enter rule like "iptables -A FORWARD -s xxx -j ACCEPT" and delete it with "iptables -D FORWARD -s xxx -j ACCEPT".. but if that rule contain some random comment (-m comment) then ... ? I can find with scripting... (2 Replies)
Discussion started by: darkman_hr
2 Replies

5. Shell Programming and Scripting

how to find the value of a variable in zsh?

I have a zsh script written by someone else, I am trying to modify it to work on slightly different data -problem is I know nothing about shell scripting. I am trying to muddle through this myself since I need to learn but can someone tell me how to debug a script? ie. I want to display the value... (6 Replies)
Discussion started by: cmp260
6 Replies

6. Shell Programming and Scripting

How can we use a variable value in find command

Hi All: I want to write a shell script to store OS current date - 1 day value in a variable. Current Date is: 22042010 and new value is 21042010 I have multiple files having date value in name in ddmmyyyy format for multiple day, so I want to find all the files based on the date... (3 Replies)
Discussion started by: lodhi1978
3 Replies

7. Shell Programming and Scripting

Find whether the variable holds value or not

when i run a select query in database, it will return the objid based on the condtion. If there is no objid tht meets the condition, I will not get any value returned and the variable will hold nothing... so now how to chk tht the variable is blank or not. I tried the below piece of code: if ;... (6 Replies)
Discussion started by: harish409
6 Replies

8. UNIX for Advanced & Expert Users

Find a environment variable Value !

There is shell script which contains some variables . These variables are used , but they have declared in the script. I think its a environment variable, so I want to know where these variables are set and given values In .profile or .login..or where to c Please give the full path and file... (3 Replies)
Discussion started by: tkbharani
3 Replies

9. UNIX for Advanced & Expert Users

Find a environment variable Value !

There is shell script which contains some variables . These variables are used , but they have not declared in the script. I think its a environment variable, so I want to know where these variables are set and given values In .profile or .login..or where to c Please give the full path and... (1 Reply)
Discussion started by: tkbharani
1 Replies

10. Shell Programming and Scripting

Find and replace the value in a variable

I have a variable whose value is I="user1:x:1100:1200:ID for user1:/home/user1:/bin/ssh-dummy-shell" I want to replace the last part '/bin/ssh-dummy-shell' with '/bin/true' I tried using sed but it garbled sed 's/\/bin\/ssh-dummy-shell/\/bin\/true' $I Thanks for the help (5 Replies)
Discussion started by: aajmani
5 Replies
Login or Register to Ask a Question