Thursday, August 14, 2014

Solution using a binary wrapper (with suid bit)

Solution using a binary wrapper (with suid bit)

1) Create a script (preferrably .sh) that contains what you want to be ran as root.
# cat > php_shell.sh <<CONTENT
  #!/bin/sh
  /sbin/service sshd restart
CONTENT
2) This file should be owned by root, and since it will later run with root permissions make sure that only root has permission to write to the file.
# chown root php_shell.sh
# chmod u=rwx,go=xr php_shell.sh
3) To run the script as root no matter what user that executes it, we will need a binary wrapper. Create one that will execute our php_shell.sh.
# cat > wrapper.c <<CONTENT
  #include <stdlib.h>
  #include <sys/types.h>
  #include <unistd.h>

  int
  main (int argc, char *argv[])
  {
     setuid (0);

     /* WARNING: Only use an absolute path to the script to execute,
      *          a malicious user might fool the binary and execute
      *          arbitary commands if not.
      * */

     system ("/bin/sh /path/to/php_shell.sh");

     return 0;
   }
CONTENT
4) Compile and set proper permissions, including the suid bit (saying that it should run with root privileges):
# gcc wrapper.c -o php_root
# chown root php_root
# chmod u=rwx,go=xr,+s php_root
php_root will now run with root permissions, and execute the commands specified in php_root.sh.

If you don't need to the option to easily change what commands that will be executed I'd recommend you to write the commands directly in wrapper.c under step 4. Then you don't need to have a binary executing a external script executing the commands in question.
In wrapper.c, use system ("your shell command here"); to specify what commands you'd like to execute.

Sunday, June 1, 2014

Sain Smart LCD + Arduino Uno for voltage readout


Here is the code:

#include <LiquidCrystal.h> // include the LCD library
LiquidCrystal lcd( 8, 9, 4, 5, 6, 7 );

int VinPin = A5; //Voltage input pin
int VinValue1 = 0;
int VinValue2 = 0;
int TimeValue1 = 0;
#define NUM_SAMPLES 10

int sum = 0;                    // sum of samples taken
unsigned char sample_count = 0; // current sample number
float voltage = 0.0;            // calculated voltage

void setup() {
    lcd.begin(16, 2); // lcd rows and columns
    lcd.print("Volts  %   Hours"); // title of sorts
}

void loop() {
     while (sample_count < NUM_SAMPLES) {
        sum += analogRead(A5);
        sample_count++;
        delay(10);
    }
    voltage = ((float)sum / (float)NUM_SAMPLES * 5.015) / 1024.0;
    VinValue1 = analogRead(VinPin) / 10;
    VinValue2 = VinValue1 / 1.02;
    lcd.setCursor(0, 1);
    lcd.print(voltage);
    lcd.setCursor(7, 1);
    lcd.print(VinValue2);
    delay(100);
    lcd.setCursor(13, 1);
    TimeValue1 = VinValue2 / 12;
    lcd.print(TimeValue1);
    sample_count = 0;
    sum = 0;
    delay(1);
}

Sunday, October 20, 2013

HD flight cam, then nice tumble, rebuild....




i crashed that copter today and it needs a rebuild, but i learned things...i know which parts to build better in the shop. so we push limits and the crash is a part of the learning. we don't not play music because we played a bad chord, the art transcends, so we play the chord the way we want next time, we know the rest of the song...

Friday, July 26, 2013

Pololu just shipped two of these to the lab!!!!!!!!!! - Pololu Simple High-Power Motor Controller 24v23

Holy moly I cannot wait to put these on RCHL v1! She is going to be moving around the parking lot by morning. It has been a long road getting her to this point. I will stream progress and post pictures of the build tonight. Also on Monday or Tuesday we should have the control board for SARA. I will try to get the both of them working together and see if RCHL can become a landing/charging station for SARA. Awesome!