C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 7th, 2003, 06:14 PM
linh linh is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 245 linh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 27 sec
Reputation Power: 6
Bug in code

#include <stdio.h>

main()
{
system("for i in `cat /etc/samba/smbpasswd|awk '{split($0,a,\":\"); "
"if ((substr(a[1],1,1)!=\"#\") && (a[1]!=\"admin\")) print a[1]}'` "
"do "
"echo -n -e \"SMBUser\t\t\t$i\t\t\"`du -ks /home/$i | "
"awk '{print (($1*1024)/1000000)}'`\"\n\" "
"done");
}

Reply With Quote
  #2  
Old July 7th, 2003, 07:14 PM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 3,977 dwise1_aol User rank is Colonel (50000 - 60000 Reputation Level)dwise1_aol User rank is Colonel (50000 - 60000 Reputation Level)dwise1_aol User rank is Colonel (50000 - 60000 Reputation Level)dwise1_aol User rank is Colonel (50000 - 60000 Reputation Level)dwise1_aol User rank is Colonel (50000 - 60000 Reputation Level)dwise1_aol User rank is Colonel (50000 - 60000 Reputation Level)dwise1_aol User rank is Colonel (50000 - 60000 Reputation Level)dwise1_aol User rank is Colonel (50000 - 60000 Reputation Level)dwise1_aol User rank is Colonel (50000 - 60000 Reputation Level)dwise1_aol User rank is Colonel (50000 - 60000 Reputation Level)dwise1_aol User rank is Colonel (50000 - 60000 Reputation Level)dwise1_aol User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Month 4 Days 5 h 26 m 2 sec
Reputation Power: 558
The if-statement in a bash script requires a "then". Also in bash, if you put more than one statement on a single line, then you need to separate them with a semicolon.

I would recommend that you get that command to run first as a multi-line script, then as a single-line script. Or better yet, have system() call the multi-line script.

Reply With Quote
  #3  
Old July 8th, 2003, 10:25 AM
linh linh is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 245 linh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 27 sec
Reputation Power: 6
I ran that Bash script in Bash without a "then" and it it did run.

I ran that Bash script in Bash without a "then" and it it did run.

As for the format, the example below does worked. String concatenation is done by having double quotes around the text.
A semicolon before an "fi"
A blank space before a text begin within [[
A blank space aftera text ended within ]]

========================================

#include <stdio.h>

system("if [[ `cat /etc/sysparam.conf|grep EnableDHCP "
"| awk '{print $2}'` = 0 ]]; "
"then killall dhcpd; "
"fi");

Reply With Quote
  #4  
Old July 8th, 2003, 10:45 AM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 3,977 dwise1_aol User rank is Colonel (50000 - 60000 Reputation Level)dwise1_aol User rank is Colonel (50000 - 60000 Reputation Level)dwise1_aol User rank is Colonel (50000 - 60000 Reputation Level)dwise1_aol User rank is Colonel (50000 - 60000 Reputation Level)dwise1_aol User rank is Colonel (50000 - 60000 Reputation Level)dwise1_aol User rank is Colonel (50000 - 60000 Reputation Level)dwise1_aol User rank is Colonel (50000 - 60000 Reputation Level)dwise1_aol User rank is Colonel (50000 - 60000 Reputation Level)dwise1_aol User rank is Colonel (50000 - 60000 Reputation Level)dwise1_aol User rank is Colonel (50000 - 60000 Reputation Level)dwise1_aol User rank is Colonel (50000 - 60000 Reputation Level)dwise1_aol User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Month 4 Days 5 h 26 m 2 sec
Reputation Power: 558
Whoa there!

I just saw that in your reply, you used square brackets around the if-statement's condition, whereas in the original post you used parentheses. Also, you terminated the if-statement properly with "fi", which was missing in the original post.

Does this modified form also not run in your program?

The only other question I would have is why you have double brackets instead of just one.

Reply With Quote
  #5  
Old July 8th, 2003, 11:25 AM
linh linh is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 245 linh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 27 sec
Reputation Power: 6
reply

1) I did modified the original code with square brackets around the if-statement's condition, and with "fi" but it does not run.

2) I tested the code again using single brackets and it does worked.

system("if [ `cat /etc/sysparam.conf|grep EnableDHCP "
"| awk '{print $2}'` = 0 ]; "
"then killall dhcpd; "
"fi");

===================================

Reply With Quote
  #6  
Old July 8th, 2003, 12:06 PM
Onslaught's Avatar
Onslaught Onslaught is offline
/(bb|[^b]{2})/
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Nov 2001
Location: Somewhere in the great unknown
Posts: 4,840 Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 2 Days 36 m 16 sec
Reputation Power: 89
Send a message via ICQ to Onslaught
lihn, I have a question for you...

Why do you insist on executing bash code through the system function?

If you want to do bash, then do bash. If you need the functionality of bash, the make a bash file and call the file through the system function. This does more than just clean up your code and make it a little easier to understand, but it also seperates out the logic.

Reply With Quote
  #7  
Old July 8th, 2003, 12:23 PM
linh linh is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 245 linh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 27 sec
Reputation Power: 6
Bash code within C

I am trying to make the code more secure by converting existing Bash code file into C so that once the user purchase the box and if they hack into it, they will see binary file not bash code where they can easily read the file and do other things.

Of course, I do know that when you compile a C program that call a Bash command like system("ifconfig"), the ifconfig will showed up as text in the binary executable file making it easy for anyone to guess what 's going on. That is why I write some of the code in C, while some remain as C calling Bash command.

Reply With Quote
  #8  
Old July 8th, 2003, 12:31 PM
Onslaught's Avatar
Onslaught Onslaught is offline
/(bb|[^b]{2})/
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Nov 2001
Location: Somewhere in the great unknown
Posts: 4,840 Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 2 Days 36 m 16 sec
Reputation Power: 89
Send a message via ICQ to Onslaught
If they are able to hack the box though (unless the root password is easily guessed) then they would most likely be able to figure a good deal out just by looking through the executable or use some other exploit to see what is going on.

For the most part though, even if they did hack the box and read what the bash script did, it could still be made so that it is obscure enough that they wouldn't know what is going on. You can always make the bash file some obscure name in some obscure directory, etc...

But, if you really want to break it down like that, then you really need to call as little bash as necessary. Like in the code example you listed, the only thing you should send to the system function is the killall dhcpd command. The rest of it should be done inside of the program. The less you send to the system function the better.

Reply With Quote
  #9  
Old July 8th, 2003, 11:45 PM
kubicon's Avatar
kubicon kubicon is offline
pogremar
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jul 2003
Location: At Work
Posts: 950 kubicon User rank is Corporal (100 - 500 Reputation Level)kubicon User rank is Corporal (100 - 500 Reputation Level)kubicon User rank is Corporal (100 - 500 Reputation Level)kubicon User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 15 h 57 m 55 sec
Reputation Power: 7
why is using the system function bad?

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Bug in code


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT