Howto: Oscam init scripts, running multiple Oscam instances and Oscam hardening

There are 25 replies in this Thread which was already clicked 23,417 times. The last Post () by zipto.

    • Official Post

    All Credit to copyleft from oscam.to



    PART I
    Prerequisits:

    I assume you have compiled/downloaded Oscam so you got 2 binaries, "oscam" and "list_smargo"
    Installation:
    as user "root" you do:


    Code
    sudo su -
    mkdir -p /opt/oscam/{bin,conf,init}
    cp oscam /opt/oscam/bin/oscam_svn_v1.23_build1234
    chmod +x /opt/oscam/bin/oscam_svn_v1.23_build1234
    ln -s /opt/oscam/bin/oscam_svn_v1.23_build1234 /opt/oscam/bin/oscam.bin
    cp list_smargo /opt/oscam/bin/list_smargo_svn_v1.23_build1234
    chmod +x /opt/oscam/bin/list_smargo_svn_v1.23_build1234
    ln -s /opt/oscam/bin/list_smargo_svn_v1.23_build1234 /opt/oscam/bin/list_smargo


    Creation of an Oscam instance:
    Now I will create my first instance and I call it "hotbabe1"


    Code
    mkdir /opt/oscam/conf/hotbabe1


    I place my config files (oscam.conf, oscam.server, oscam.user ...) for Oscam instance "hotbabe1" into "/opt/oscam/conf/hotbabe1"
    Now I create the init script for Oscam instance "hotbabe1"


    Code
    touch /opt/oscam/init/oscam.hotbabe1
    chmod +x /opt/oscam/init/oscam.hotbabe1


    Now copy the following code into "/opt/oscam/init/oscam.hotbabe1"



    Install the sript with:


    Code
    ln -s /opt/oscam/init/oscam.hotbabe1 /etc/init.d/


    Now you should be able to "start/stop/restart/status" your very "hotbabe1" Oscam instance
    Just run:


    Code
    service oscam.hotbabe1 status
    service oscam.hotbabe1 stop
    service oscam.hotbabe1 start
    service oscam.hotbabe1 restart


    Now for every additional Oscam instance we choose a different name e.g. "hotbabe2" and repeat the steps in "Creation of an Oscam instance:",
    and change the variables "OSCAM_CONF_DIR" and "PROCESSNAME" in the start script of the new instance.
    Note that you have to choose a different port/ports for every new instance in the "oscam.conf" when running multile instances!


    PART II
    Now once you have lots of running instances and hopefully lots of RAM :)
    you need to manage them all easily. Thus we need a master Oscam init script.
    I call it "oscam"


    Code
    touch /opt/oscam/init/oscam
    
    
    
    
    chmod +x /opt/oscam/init/oscam
    ln -s /opt/oscam/init/oscam /etc/init.d/


    Copy the following code into "/opt/oscam/init/oscam"



    Now you can manage all of your Oscam instances by running:


    Code
    service oscam status
    service oscam stop
    service oscam start
    service oscam restart


    PART III
    First I will go through hardening Oscam on GNU-Linux OS level.
    As you can see I use a "RUNASUSER" variable in the init script of the oscam instance.


    When using oscam as a card reader we set it to run as root, as we need root privileges to write to the USB-device file of the card reader.
    Another aproach would be writing a udev-rule to change the owner/permissions of the device file when it is created.
    E.g. find out what device class does your reader belong to under GNU-Linux ... write an udev rule .... and then set the "RUNASUSER" variable to an unpriviliged user.


    But when using Oscam as a proxy or as a frontend server to other (not trusted internet) clients, then hardening comes into play.
    So these are the steps to harden your Oscam server.


    Code
    groupadd -g 34523 oscam
    useradd -d /dev/null -g 34523 -u 34523 -s /bin/false oscam


    Now we just set "RUNASUSER" to oscam e.g. RUNASUSER="oscam" in the oscam instance init script and restart oscam.
    Now oscam is running as a non priviliged user with no shell and no home directory.
    There are no performance issues with this setup.
    By doing so it is hard to break in into your system now.


    Now we need to harden Oscam and protect your cards on CS level. To do so just check the "ecm whitelisting option in oscam.conf"
    Also only allow EMM from trusted clients.
    Best practice is also to handle most "untrusted" ECM traffic via caching.



    P.S. in the next toturial I will introduce you with a watchdog that I have written for Oscam.
    Also a tutorial on how to protect your server against synflooding and port nocking attacks will follow.


    Cheers

  • hello,
    I try to run two different oscam in ubuntu; is what you could help me edit your script
    thank you in advance



  • Looking to setup 2 instances of oscam on my pc server (one for cs and the other for cache only)


    Can I just set them up so:


    Place a copy of oscam named 'oscam1' along with my 'oscam'(which I already have running) in to /usr/local/bin


    oscam 1 looks to /usr/local/etc for its configs
    oscam 2 looks to /usr/local/etc/configs2 for its configs


    Then would I just have to edit the init to start them both on boot?


    Or do I have this all wrong and it's not that simple?


    Thanks.

  • So how will the second oscam know to look in a different location for its configs?


    You will have to start it with -c flag pointing it to where the configs are, like this:
    /usr/local/bin/oscam1 -b -c /usr/local/etc
    /usr/local/bin/oscam2 -b -c /usr/local/etc/configs2

  • You will have to start it with -c flag pointing it to where the configs are, like this:
    /usr/local/bin/oscam1 -b -c /usr/local/etc
    /usr/local/bin/oscam2 -b -c /usr/local/etc/configs2


    Also add a second tmp directory.. :


    /usr/local/bin/oscam1 -b -c /usr/local/etc
    /usr/local/bin/oscam2 -b -c /usr/local/etc/configs2 -t /tmp/.oscam2

  • having big problems getting this working as all my directories are different to the one in the tut above and i've never really done init scripts before any help?



    What do you want to "init" ?
    Do you just want to start the two oscam's on boot ?


    If so, edit /etc/rc.local


    and add the two startup commands (from previous posts) for both oscam's, just above the exit 0 statement.


  • Yes, just add these. The -c parameter sets the config directory.

  • I have a problem getting this to work.
    I installed the second oscam ( named USERCAM ) and it works perfect. I can start/stop/restart etc with the script but i have a problem regarding the oscam check.
    I have a script called OscamCheck.sh and it checks every 5 minutes if oscam is running (for the original).
    However if i close the first oscam the script still thinks that oscam is running because of the second instance although it has the name USERCAM.


    Does anyone know how i can fix this issue so that the OscamCheck.sh wil ONLY check for the MAIN oscam and not for the seconds oscam ( usercam ? ). I want to create a seperate script for the 2nd oscam.


    The script has the following lines:



    Thanks in advance

  • hi


    whe i try to start oscam i get this error


    Code
    root@server ~ > service oscam start
    starting oscam.hotbabe1!
    Segmentation fault
    Failed to start oscam.hotbabe1. Exiting!
    root@server ~ >


    what i can do to solve this problem ?


    thx




    No help here on this board ?


    No help here on this board ?


    Please help me !


    I use debian lenny



    Sent from my iPhone using Tapatalk

  • With debug level 1 i get a restart from oscam all 8 Minutes. Is the watchdog script still ok? I have oscam 1.20 svn 8630 running.


    In the log comes the message..
    2013/05/07 19:56:29 No successful cw transaction for 120 sec. Restarting oscam.hotbabe1!
    2013/05/07 20:04:02 No successful cw transaction for 120 sec. Restarting oscam.hotbabe1!
    2013/05/07 20:11:35 No successful cw transaction for 120 sec. Restarting oscam.hotbabe1!



    But oscam is running without failure..
    Could it be, that the script is not running with new oscam versions? I use oscam watchdog version 1.2 from here


    Regards
    telecomic

  • Hey,


    I have followed this how to thoroughly and performed ...
    on my server is to use debian 7.0


    but keep getting the following error command:

    Quote

    env: /etc/init.d/oscam: File or directory not found



    Code
    service oscam status
    service oscam stop
    service oscam start
    service oscam restart



    about help from you I would be very grateful


    friendly greetings


    mate


  • I don't use this method, but have you checked the permissions for the oscam binaries?
    If you have not set them to 755, do so & report back.


    I use a slightly less complicated method to start on boot & check if all instances of oscam are running.
    I just add the the lines to start each seperate oscam binaries to the rc.local
    e.g.

    Code
    /usr/local/bin/oscam1 -b -c /usr/local/etc/oscam1 -t /usr/local/tmp.oscam1
    /usr/local/bin/oscam2 -b -c /usr/local/etc/oscam2 -t /usr/local/tmp.oscam2
    /usr/local/bin/oscam3 -b -c /usr/local/etc/oscam3 -t /usr/local/tmp.oscam3


    & I have a check script for each instance of oscam running every 5 mins from crontab...


    e.g.


    Code
    */5    * * * * root    /usr/local/bin/oscam1-checker >/dev/null
    */5    * * * * root    /usr/local/bin/oscam2-checker >/dev/null
    */5    * * * * root    /usr/local/bin/oscam3-checker >/dev/null


    But in saying that, I am of late having issues once a week or so of duplicate instances starting up so I might give this tut a go..




    All your problems have been solved countless times before so try the search box before you post!!
    Please do not Request help by PM, use the main forum so Everyone can benefit from the answers.

  • Quote

    Can you post your script for check oscam is running?



    Here is the script I use in my setup.


    Bash
    #!/bin/bash
    if ! ps x |grep -v grep |grep -c "oscam1" >/dev/null
     then
            echo "ok - oscam1 seems running" && echo `date "+%d/%m/%y %R Starting oscam.."`  >> /var/oscamlog/oscam1.check
            oscam1-c /usr/local/etc/oscam1 -t /usr/local/tmp.oscam1
     else
            echo "ok - oscam1 seems running" && echo `date "+%d/%m/%y %R Oscam1 was checked - Running OK"` >> /var/oscamlog/oscam1.check
    fi


    I use a separate scripts for each instance of oscam..
    But as mentioned above, lately I am getting duplicate instances of oscam starting up, so if any linux guru's can see a problem, i would appreciate the tip..




    All your problems have been solved countless times before so try the search box before you post!!
    Please do not Request help by PM, use the main forum so Everyone can benefit from the answers.

  • Hi;


    I'm blocked in the first step when I execute "cp oscam /opt/oscam/bin/oscam_svn_v1.23_build1234"
    can't find oscam_svn_v1.23_build1234 in the bin folder
    Can I rename the oscam to oscam_svn_v1.23_build1234 and put it in bin folder at the begin?


    Thanks in advance

OSCam Support Forum

Configs, discussion, downloads and guides for OSCam Softcam.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!