Friday, August 6, 2010

CCcam Monitoring / Firewalling - Protect your cccam server

- UPDATED -
Changelog :

Quote:
Version 2g :
- updated for cccam 2.1.2, now compatible with 2.0.x and 2.1.x
- added simple startup script
- reverted scripts to default shell executor "/bin/sh"
- minor fixes and syntax changes
Hi,

this set of scripts will help you protect your cccam server against various events (bad command and illegal logins) generated by your peers in order to increase cccam service stability.
The basic idea is to use the linux firewall (iptables) in "realtime" to block cccam traffic for specific peers (ip) based on cccam debug output.

This work was initialy inspired by discussions on this thread "How to solve the disconnecting client issue" and is a partial answer to that specific cccam problem.

Although all of it was designed on a debian standlone cccam server having a local firewall, it should also work if your firewall is on a remote machine on your local network.

The Dreambox setup is still NOT working at the moment and will be discussed at the end of the tutorial.


I have been using the scripts for many months with cccam 2.0.10 / 2.1.0 / 2.1.2. I didn't notice any cccam crashes or problems with peers. My server has 50-70 peers and gets between 30 and 100 bad commands a day but their effect is barely noticeable.

Concerning CCcam 2.1.2, my tests showed increased problems with peers regarding the login process, leading to numerous peer bans and peers disconnections. Something has definitely changed in that cccam version that was not present in cccam < 2.1.2.

I personally reverted to cccam 2.1.0 (you can probably use 2.1.1 safely too) and won't be using 2.1.2, i'll wait for 2.1.3 and see what happens then, i suggest you do the same unless you're satisfied with 2.1.2.

The only advantage i can see with 2.1.2 is that it lets my script ban login floods, i'll work on that feature for cccam < 2.1.2 when i have time, for it is the last missing protection i can think of regarding cccam problems, i also noticed some ecm requests floods but i probably never will filter thoses.

Features :
- block peers based on a specific number of bad commands or slow "cards" commands, for any number of minutes.
- block peers doing "illegal logins" (no account or bad password) for any number of minutes.
- protect cccam accounts or ips from being blocked or give them a different error count.
- filter main log and keep only relevant information (reduce log size) and split logs (monitoring, ecm, logins).
- modify monitoring behaviour, turn on/off firewall blocking or logs without having to restart cccam.
- iptables rules use user defined chains in order to keep your iptables firewall fast, clean and safe.



Prerequires :
- cccam running in debug mode with timestamps (-d -t)
- iptables (optional - can be disabled to use only logs)
- sudo to access iptables for your cccam user, with or without password (optional - sudo can be omitted or use of ssh to manage an external firewall)
- cron to perform iptables flush rules (unban) (optional if iptables is not used)
- bash/sh/ash(/busybox) POSIX shell script (read the dreambox section for more info on the scripting problems with ash/busybox shells) and some basic shell commands cat, echo, cut, grep..



Install :
There's not much to do if you know that your system matches the prerequires above.

Open a command line window and make sure you are running your cccam user.
Put the scripts start.sh config.sh fork.sh monitor.sh iptables.sh, in your cccam directory along with the two "protected_account" "protected_ip" files if you need them.

Make sure the scripts can run on your shell, to do that first find out which shell you are running, there's a great change your linux system has links to simulate the precense of sh or bash but you can check your installed shells with the "whereis" command ("#whereis sh", "#whereis ash"...).
The scripts should be POSIX compatible to run on most shells and are configured to run on ash which is supposed to be faster than sh/bash, with the exception of "fork.sh" which MUST run on sh/bash or any shell that will release terminated child scripts and won't generate zombie processes (defunct).
If you don't want to install or use "ash" you can edit each script and change their top line :
Code:
#!/bin/ash
with something matching your shell, like :
Code:
#!/bin/bash
You need to edit/copy config.example.sh to config.sh, and make config.sh match your setup, each config line has comments.
Make sure you get the iptables parameters right if you intend to use it.

Be very careful to properly set CCCMODE to match your cccam version !

fork.sh will try to create the necessary directories LOGDIR and WORKDIR (see config.sh), but if for some reason it doesn't work and shows errors, create two subdirectories to put logs and work files, default directories are "logs" and "monitor", path are defined in config.sh and can be set to whatever you'd like :
Code:
cd /path/to/cccam
mkdir monitor
mkdir logs
chmod 0775 logs monitor
Make sure the scripts are executable :
Code:
chmod +x  start.sh config.sh fork.sh monitor.sh iptables.sh
You can test your iptables setup by running the init command :
Code:
./iptables.sh init
iptables init is always run when the fork.sh script starts so you don't actually need to run the init command manually but if your get some errors you will have to fix them.
If you run the init multiple times you will have two errors "iptables: Chain already exists", this is not a problem.

Errors are redirected to you main log file (default "logs/monitor.log") so read it to see if errors appear.

Make sure cccam output looks like this :
Code:
12:15:21.499 CCcam: deleting client xx.xx.xxx.xxx(userX), bad command
12:15:21.501 CCcam: deleting client yy.yyy.yyy.yy(userY), read result -1
12:15:27.896 CCcam: 1498 cards --> client yy.yyy.yyy.yy(userY) (took 0.2730 seconds)
you can test that by running cccam in the foreground with :
Code:
./CCcam.x86 -d -t -C ./CCcam.cfg
according to cccam --help, the only thing that could be missing is the timestamp. Although i think that -d activates debug mode, not only foreground, and then outputs everything including timpestamps, also overriding cccam config options like DEBUG..


Finally when you're all set you can run cccam with the following command from the cccam directory :
Code:
./CCcam.x86 -d -t -C ./CCcam.cfg | ./fork.sh >> /path/to/cccam/logs/monitor.log &
Or use the start.sh script :
Code:
./start.sh start
start.sh has to be placed in the same directory as the other scripts and has the following commands "start / stop / restart". It uses regular ps/kill commands so it should be compatible with most systems. And can be used to monitor cccam status and restart it if necessary so you can use the "start" command in your cron to check if cccam has crashed and restart it.


You can then check out the main log with :
Code:
tail -n30 -f logs/monitor.log
if everything works fine and you are using the firewall, you have to add a cron command to flush rules when they expire.
Code:
*/1 * * * * /path/to/cccam/iptables.sh flush >> /path/to/cccam/logs/monitor.log 2>&1
It will run the iptables flush script every minute and delete rules that have expired (exceeded the ban duration)




Usage :

CCCam 2.1.0/2.1.1 specific :
Those two versions produce a lot more "bad command" events than other versions because some events were renamed as bad commands and were not before, knowing that i'd suggest being a little more tolerant regard the bad command counts and bans if you notice a large number of bans, so you could use settings like the following :

Code:
BADDELAY=2               # bad command count duration in minutes
BADCOUNT=5              # bad command count
BADCOUNT_IG=10        # bad command count for protected accounts
BAN=60                      # ban duration in minutes

- CCCMODE : defines your cccam version, important if you want this script to work. Basically there's one mode "0" for all cccam but 2.1.2, and one mode "1" for cccam 2.1.2 and probably upcoming cccam revisions.

- BADCOUNT/BADCOUNT_IG : Knowing that any peer can generate a bad command it is probably not a good idea to ban them at the first one. A good peer will most likely succeed to connect on its second attempt.

- BADDELAY/BAN : bad commands being mostly caused by networking problems (probably very slow lines) it can be something temporary. That's why a 120min ban is usually enough to let the peer try again at a later time when the network conditions have changed. Using a short ban duration like 30min or less will simply let the bad peer send more commands and cripple your cccam server. If you let a peer send more than one bad command then the error count spreads accross the BADDELAY duration.

- BANLOGIN : banning illegal logins is optional but after exchanging Clines with many peers you will find out that a bunch of them won't remove your Cline, getting your cccam server to handle a large amount of login attempts that are all doomed to failure. I just thought that filtering that traffic wouldn't hurt (read bugs and limitations below). It should also protect your server from brute force login attacks although i doubt anyone would try to do such a visible hack.

- LOGUNKNOWN/UKNOWNMAINLOG : are used to help cccam identify accounts that produce some events. LOGUNKNOWN will tell cccam to look for missing account names for the event processed by looking at current work/temp files. In addition, the optional UKNOWNMAINLOG will let cccam look into the main log file, this can be very helpful but can also produce some nasty side effects if your main log is big. So you should make sure to manage (rotate/purge on a daily basis) your main log file if you intend to use that option.

- CARDSDELAY/CARDSBAD : for CCcam 2.0.x-2.1.1 - has no impact on cccam 2.1.2 . That one is a bit more tricky, it tells the monitoring script to interpret "xxxx cards --> client" commands as a bad command based on its duration. I have indeed noticed that peers taking very long time (a few seconds) to receive the cards info will disconnect active peers in the exact same way a bad command does ! Unfortunately i wasn't really able to identify a very precise duration above which diconnections happen so i used a two levels trigger to manage those commands.
CARDSDELAY is the max durations in seconds above which the peer will get a "bad command" added to its log, but it will never trigger a ban action, the trigger will only log the event and when a "real" bad command occurs at a later time then it will count as a bad command. The use of this option is quite restrictive, the default is 4 seconds.
CARDSBAD is the max number of seconds allowed for a "xxxx cards --> client" command, above which a ban action is triggered, as if a real bad command was seen. CARDSBAD is probably more important than CARDSDELAY because it will actively try to ban peers with a very slow network, it will act in the exact same way as a bad command action does, respecting the same ban trigger options (BADCOUNT/BADDELAY). CARDSBAD should always be greater than CARDSDELAY.

- DEBUG : adds some debug data to a $LOGDIR/debug.log file. Probably of no interest to you and should stay disabled (=0).

- Understand that when a peer is banned, he will see your server as offline but you will still be able to connect to his, you know what that means.



Files :
Version 2g : Download
("protected_account" and "protected_ip" are two empty files in which you can put account names and ips, one by line, that you want to "protect" from basic ban rules, see the documentation above for details)



Advanced :
- you can rotate logs, all redirects use "append" (>>).

- no sudo password
you can allow access to iptables for your cccam user (if not root) without sudo password by adding the following line to your "/etc/sudoers" file.
Code:
cccamuser   ALL=NOPASSWD:/sbin/iptables
That way you don't have to give a large sudo access to your cccam user and you don't have to put a sudo password in config.sh SUPASS option. The cccam user only requires sudo (root) access to iptables, nothing else.

- using a remote firewall
To use a remote iptables firewall on your local network you will have to replace the sudo command with a ssh one. ssh will try to connect to a remote linux system and execute the iptables command there, then return the command output to the script making the iptables command run exactly as if it was executed localy.
I will guide you quickly through a basic ssh setup but if you don't know what you are doing i'd suggest googling some SSH HOWTOs.

A proper SSH setup would be as follows :
As root, generate a key pair using your "cccam" system's (where cccam monitoring script runs) ssh key generator (ssh-keygen on debian), if any, with the following command :
Code:
ssh-keygen -t dsa
When asked for a "passphrase", we won't enter one. Just press enter twice.
That should produce two files in your root home directory : "~/.ssh/id_dsa.pub" and "~/.ssh/id_dsa"

Copy the one line content of the new "~/.ssh/id_dsa.pub" file to the following file on your remote server root user directory : /root/.ssh/authorized_keys2
Depending on your remote server ssh configuration, the file could also be : /root/.ssh/authorized_keys

Now from the cccam system you should be able to ssh your remote server with the command :
Code:
ssh root@remoteip
If it asks you to keep a footprint of the new remote system, say yes and it shouldn't bother you with that later, you can "exit" ssh now.
If it worked you can also try accessing the remote iptables firewall with that command, from the cccam system :
Code:
ssh root@remoteip /usr/bin/iptables -L -n
It should display your firewall configuration for INPUT OUTPUT FORWARD chains.

Then set the SUDO option in config.sh, like this :
Code:
SUDO="/usr/bin/ssh -x root@remoteip"
you can also empty the SUPASS option.

in order to make sure you have a working remote iptables setup you can try running the iptables.sh init command from the cccam system, as follows :
Code:
./iptables.sh init
If you run it twice it should display two errors : "iptables: Chain already exists"
That means the cccam chains have been created on your firewall and your setup works.

You can now run cccam as described in the main install guide above.




Known bugs and limitations

- log file output lines may be missplaced, some commands take longer to execute than others and the command output then gets into the log file a bit late, but this is usually something very localized and every line having a timestamp you can always understand what happened.

- some iptables rules may be insterted more than once when a event is not processed fast enough, but it doesn't matter because iptables won't mind and the flush script makes sure duplicate rules are removed.

- reloading your firewall should delete cccam init. you will have to init cccam iptables manually to fix that, with "./iptables.sh init". The good thing is that it should not get the scripts or cccam to crash, so cccam will not really care but you will get lots of errors in your cccam monitoring log..

- banning illegal logins will most certainly ban the new peers you have exchanged Clines with if you haven't activated their accounts before sending them the Clines. You will then have to remove the ban manually or wait for the iptables flush to purge it for you if you haven't banned illegal logins permanently, otherwise new peers may never be able to connect !



Dreambox

Although the scripts should run (with ssh and remote firewall) on dreambox busybox default shell (ash), as they do on my debian stable busybox (1.1.3) binary, the problem i have with that shell, or with ash (dash on debian), is that a parent script will not "release" child scripts that have ended and will then generate tons of zombie processes also known as defunct processes.

If you know a way around that busybox ash shell problem, please contact me, it will most certainly be very helpfull to dreambox users.

I must stress out the fact that running the scripts as they are on the dreambox will work for a short period of time and then stop working when the large number of defunct processes will have filled the system's proc table. It will also most certainly make the dreambox system pretty unstable or even make it crash..

How to setup CCcam/Newcs with Omnikey cardsharing server with ClearOS 5.2 Linux

This tutorial helps you to setup a Linux PC CCcam server under 1 hour, even for users with no Linux knowledge.

We need some old working PC. Hardware: Pentium 3 or Amd 600Mhz and up, 256mb (512mb optimal) ram, from 5gb HDD and up, Networkcard, and a simple 1mb, 4mb, 8mb... or onboard videocard (no need a fancy 128mb AGP/PCI-E videocard).

Intro:
Out there are many Linux distro's. With most of them you can build a good share server, but we use today "ClearOs".

What is ClearOs you ask!? ClearOs is a powerful network and gateway server designed for small organizations and distributed environments. Though ClearOs comes with an extensive list of features and integrated services (see sidebar), the solution is easy to configure thanks to the intuitive web-based interface. ClearOs Homepage

Is it stable!? Yes it is very stable and works almost perfectly with CCcam.


OK lets start now.

1: Download and burn it to a CD. Link for ClearOs iso:
ClearOS Enterprise 5.2


2: Installation steps:
1) Choose a Language: Installation language
2) Keyboard Type: Your keyboard language
3) Installation Method: Local CDrom
4) Install Type: Install
5) To Proceed with the installation type "ClearOs"
6) System Mode: Standalone Mode
7) Specify Lan IP Address: Manual Configuration (Set dynamic ip configuration if your router support MAC based static lease)
8) Nameserver IP: your router gateway IP (example 192.168.1.254 or what u have there)
9) Set The System Root Password
10) Partitioing: Use default
11) Select Software Modules: Now with new ClearOs you can choose install "Graphical Console" (GUI), or without it. "Intrusion Detection And Prevention" is pretty cool thing against the hackers and prevents smaller DDOS attacks. Everything else you can tropp. You can install missing modules easy later under dashboard directly if needed.


3: Now if ClearOs is installed and you used manual IP table then you can unplug monitor and keyboard from PC you do not need them anymore.
If you used automatic DHCP, then log to server from current monitor and keyboard to know what IP your server has.
Use command: ifconfig
Now you see your server IP, unplug monitor and keyboard from PC.


4: System setup.
1) Write to your webbrouser next https://192.168.1.142:81 of cource your server lan IP.
2) Next u get warning message like so "This Connection is Untrusted"
Hit the tab "I Understand the Risks", then the tab "Add Exception" and at least "Confirm Security Exception" (It can happen that u need make 2-3 times that over again, when u get to the login page!)
3) Login
Username: root
Password: What u entered during the ClearOS installation
4) Language: default is English
5) Network: Please set mode to "Standalone Mode No Firewall" later if everything is working u can enable Firewall if u want it.
6) Time Zone: set your country
7) Domain: you can leave it to default "clearos.lan" or change. It is up to you.
8) Organization: fill the forms like u want, not needed to use your real data there.
9) Congratulations, you have completed the system setup wizard! and hit the tab "Continue configuring your system"
10) Finish: and again u need make that step "This Connection is Untrusted" Hit the tab "I Understand the Risks". Then the tab "Add Exception" then "Confirm Security Exception" and at last "Resend". (It can happen that with FireFox brouser u need make 3-5 times that over again, when u get to the main page back!)


5: Set up the Dashboard.
1) Hit on tab "ClearCenter" and "Register System". (If you had already ClarkConnect registered, then same data u can use forward with ClearOS as well. But if you are new user then hit that link and register your self: Register ClearOS
2) Hit on tab "ClearCenter" and "Software Modules" From there tick "FTP server module" and hit "Go". Wait, when it finish install. Depends from system speed from 2-3 minutes it can take, but you get constant info as well to when it is finish.
3) Close the dashboard window complete and open it again, then u see new Tab up there called "Server" and under that is now FTP. Next open that FTP and set "Status - Running" as "On boot - Automatic". "Maximum Instances" set down from 30 to 1
4) Open tab "Directory" and "Users" Now u have message there "The required user database engine is not running. Continue" Please hit that "Continue" tab now.
5) LDAP is used to store user and password information. Just hit there "Update" tab.
6) Open again "Directory" and "Users". Now hit the tab "Add" and fill the next form:

Code:
Username: blabla (your FTP and Home directory username)
First Name: fafa
Last Name: gaga
Password: xxxxx (your FTP access password)
Verify: xxxxx
Hit the tab "Add" to save new user data.


6: Download CCcam pack and FTP client software. Unpack CCcam pack and take out from there CCcam.x86 and CCcam.cfg.
WinSCP Free SFTP, FTP and SCP client for Windows


7: Open FTP client app add there lines like so:
Session: server
Host named: 192.168.1.15
User name: blabla that you have created under dashboard
Password: xxxxx
Now OK and connect to server.


8: Copy with FTP client CCcam.x86 and CCcam.cfg to share server. If it is done close the FTP session.


9: Now we need open Putty. If you do not have putty you can download it here: Download putty for windows PC
Log with putty to server as root not as user blabla!
Now we can put some commands to get CCcam to right place.


10: Commands: (command "ls" is directory viewer) Please give commands exactly like i write here then it works 100%!!!

cd /var
mkdir /var/bin
mkdir /var/etc
ls


Note: mkdir is command for create new directory. If you see now 2 new directory then that part is OK. Next commands are:

cd /home/blabla
ls


Note: that blabla is user what you created under dashboard and you see there CCcam.x86 and CCcam.cfg.

cp CCcam.x86 /var/bin
cp CCcam.cfg /var/etc

Note: cp is command for copy. Command rm is for delete.

cd /var/bin
ls
chmod 755 CCcam.x86
ls


Note: Now you see that CCcam.x86 is green, before it wase withe.

CCcam auto startup script:

nano /etc/rc.d/rc.local

Note: there you see line like that: "touch" and so one. under that line is lot empty space. Now please write next line exact under that "touch" line there so:

/var/bin/CCcam.x86

Note: / you can get there only with shift+7 and ctrl+o is save file and ctrl+x exit. Look out that you do not change there nothing else!

cd /var/bin
ls
./CCcam.x86


Note: ./CCcam.x86 is command to start CCcam manually from command line and command: killall CCcam.x86 stops it agan. For CCcam debuge mode use command: ./CCcam.x86 -d

cd /var/etc
ls
nano CCcam.cfg

Note: with that command you have access to cfg file to edit it or you can use tutorial 15: to set to whole server FTP access . I prefer to change cfg file over putty.


12: How to get CCcam 2.1.0, 2.1.1 and 2.1.2 working with ClearOs 5.1. CCcam 2.1.3 and 2.1.4 don´t work with ClearOs 5.1!
Please give next commands into your system command line:

cd /home/blabla
wget http://web.zone.ee/kapzas/libstdc++.so.6.0.9
ls
cp libstdc++.so.6.0.9 /usr/lib
cd /usr/lib
chmod 755 libstdc++.so.6.0.9
unlink libstdc++.so.6
ln -s libstdc++.so.6.0.9 libstdc++.so.6
/sbin/ldconfig

Note: that blabla is user what you created under dashboard!


13: Done. CCcam server is up and running. With ClearOs working most external cardreaders serial and usb with no extra linux configuration.

For serial reader in COM1 put into CCcam.cfg so:

PHOENIX READER PATH : /dev/ttyS0

If you have attached to COM2 then so:

PHOENIX READER PATH : /dev/ttyS1

COM3: ttyS2 and so one.

For attached USB1 reader like Smargo Smartreader+ so:

SERIAL READER : /dev/ttyUSB0 smartreader+

Attached USB2:

SERIAL READER : /dev/ttyUSB1 smartreader+

For USB3: ttyUSB2 and so one.


14: How to setup Infinity reader under ClearOs 2 way options:
http://www.eurocardsharing.com/f163/...-connect-96082 or http://www.eurocardsharing.com/f163/...-windows-59966 Note: "apt-get" does not work with ClearOs 5.1 anymore u need to use command "yum"

Big thanks for that Infinity reader howtos goes to Bennieboy and to Ramad


15: As lot asked how to install NewCs into ClearOs so here is tutorial how do too that. Please follow exaclty my next instruction!

cd /lib
ln -sf libcrypto.so.0.9.8e libcrypto.so.0.9.8


Download NewCs pack NewCS 1.67 RC1 and do so:
Unpack Newcs pack and take out from there 2 files: newcs.i686 and
newcs.xml.phoenix Next rename newcs.i686 to a newcs.x86 and newcs.xml.phoenix to a newcs.xml
Copy newcs.x86 to /var/bin and set chmod 755
Copy newcs.xml to /etc
Next edit newcs.xml for you needs and start newcs.x86 same way as you started CCcam: /var/bin ./newcs.x86
And for last we put newcs.x86 to server auto startup script.
If use newcs and CCcam together then palce so that newcs.x86 script is next over CCcam.x86 startup script then boots newcs.x86 first up and then CCcam.x86 like it should.
newcs auto startup script:

nano /etc/rc.d/rc.local

Note: there you see line like that: "touch" and so one. under that line is lot empty space. Now please write next line exact under that "touch" line there so:

/var/bin/newcs.x86


16: Here is tutorial how to install No-Ip under ClearOs:
You need first install cc-devel developers package to be abel to execute no-ip install commands:

yum groupinstall "Development Tools"
cd /home/blabla
mkdir no-ip
cd no-ip
wget http://www.no-ip.com/client/linux/noip-duc-linux.tar.gz
tar zvxf noip-duc-linux.tar.gz
cd noip-2.1.9-1
make
make install

Note: that blabla is user what you created under dashboard!

Put your no-ip account login/email string

Put password to that login/email

Enter update interval: [30] write to there 30 Then no-ip makes updates to your IP every 30 minute

Do you wish to run something at successful update? [N] (y/n) hit n

cd .. and agan cd ..
rm -rf no-ip and hit enter
tipe command exit to leave.
Done. You have successfuly installed no-ip under linux.
Here u can look same commands too: The Newbie's Guide to the No-IP™ Linux Client


17: Here is tutorial how to install DynDns under ClearOs Big thanks for that link goes to Bennieboy


18: Totorial how to set FTP access under ClearOs to by root and not only as user.
To enable the user that you have created to to have ftp access to the hole server you must do this steps:

1) edit file proftpd.conf: nano /etc/proftpd.conf
2) comment this line #DefaultRoot ~
you should have something like this:

# To cause every FTP user to be "jailed" (chrooted) into their home
# directory, uncomment this line.
# DefaultRoot ~

Big thanks for that FTP tutorial goes to nmga


19: If you have CCcam stabilty problem with your PC server and you have tryed everything, then here comes a help for that issue. Change from your CCcam.cfg next line:

#DVB API: -1
to a
DVB API: -1


Note: You need restart the CCcam after change. It works only with linux PC based CCcam servers. Dreambox or other reciver users do not try that!

Big thanks for that tip goes to Shalafi


20: Tutorial how to create CCcam running check script and if CCcam stops then that script runs CCcam self up again.

1) Log over putty to server as root and give next commands to create the script:

cd /etc
touch CCcamcheck.sh
chmod 777 CCcamcheck.sh
nano CCcamcheck.sh


Next copy all that inside the CCcamcheck.sh:
Code:
#!/bin/bash
if ! ps -C CCcam.x86 > /dev/null
then
    /var/bin/CCcam.x86
fi
Next hit from your keyboard ctrl+o to save and ctrl+x to exit.

2) Now we need make a cron job what executes the script every 5, or from you set minutes. Please give next commands to make a cron job:

cd /etc
export EDITOR="nano"
crontab -e

There add new line to the job list so:
Code:
*/5 * * * * /etc/CCcamcheck.sh
Note: / sign you can get there only with shift+7 !

Hit ctrl+o to save and ctrl+x to exit and test the script out if it is working. Kill CCcam from /var/bin and wait 5 minutes and CCcam should go self up agan.
Note: If you feel that 5 minutes is too long, then u can lower it.

3 minute cron:
Code:
*/3 * * * * /etc/CCcamcheck.sh
1 minute cron:
Code:
*/1 * * * * /etc/CCcamcheck.sh
I know that "CCcam running check script" is not the best one, but it works well and it is easy to use. If u want use more complicate script then they you find in forum.

Big thanks for that CCcam running check script goes to FSS


21: Tutorial how to Configure CCcamphpinfo in ClearOs Big thanks goes to gangster429


22: How to get working a cheap ID cardreader Omnikey or SCM with ClearOs 5.1.
yum install opensc pcsc-lite ccid
chkconfig pcscd on
service pcscd start

Next you need "pcsc" version of newcs. Exmple u have PC linux server, then you need newcs.i686.pcsc newcs-1_67RC1.zip Newcs conf examples and chat you find from here: How to get a Omnikey or SCM reader working with NewCs/Oscam under Linux and Windows



Good testing

Beginners guide to successful Cardsharing

Beginners guide to successful Cardsharing

1. Introduction
2. Hardware
3. Hardware installation
4. Setup your network
4.1 Fixed IP (PC)
4.2 Network setup Dreambox
4.3 Port forward router
5. Software installation Dreambox
5.1 Flash image
5.2 Install CCcam
6. Software installation (PC)
6.1 DNS Updater
6.2 Dreambox Control Center (DCC)
6.3 CCcaminfoPHP
6.3.1 Versions 0.8.2 and higher.
6.3.2 Versions before 0.8.2
7. How to find someone to share with
8. Flines and Clines the basics
9. Fake and old cards
10. Block all cards that you don’t want
11. So you want a big one
12. Last word



1. Introduction
I have seen many new members lately on this forum. At the same time many similar questions have been raised over and over again.
I’m writing this just to make it easier for new members to find answers for their questions about cardsharing.
I will focus on the use of a Dreambox as Sharing receivers and the CCcam protocol.
Remember that a newbie is just an inexperienced expert
ATTENTION! All this information is for test purpose and should only be used within your own household. No one except yourself is responsible for any damage this can cause or any law you might break.

2. Hardware
What hardware you’ll need is based on how your house looks like, where you want to watch TV, how big server you want to have and so on.
What we all need is a Dreambox of some kind.
A computer with internet connection.
If you have the computer in one room and the Dreambox in another room far away you will need either a long Ethernet cable or use another solution to connect your PC to your Dreambox.
I can recommend the use of 2 Homeplugs, it’s a really user friendly alternative.
Read more about Homeplugs here: HomePlug Powerline Alliance - Wikipedia, the free encyclopedia
If you want to be able to handle a large number of peers you need a pc as server, more about that later.

3. Hardware installation
Not much to say here.
Put your Dreambox in a suitable place by your TV.
Make sure you have enough space around it to let the air circulate freely and cool down the Dreambox.
Connect the cable from your satellite dish (if you use a satellite dish) to your Dreambox tuner.
Connect the network cable to the Dreambox.
Connect power cord.
Switch on.

4. Setup your network
To be able to share with another CCcam server or even many servers you need to set up an network.

4.1 Fixed IP PC
First of all you need a static ip in some way. Either you have one from your ISP or you can set one up for yourself.
Follow this link for static ip: PortForward.com - Free Help Setting up Your Router or Firewall

4.2 Network setup Dreambox
Now you are ready to setup the ip of your Dreambox.
You should have all information needed if you did step 4.1.
For example
PC ip = 192.168.1.141
Dreambox ip =192.168.1.142
subnet mask = 255.255.255.0
Default gateway = 192.168.1.1
DNS Server = 216.104.63.7
Remember to switch DHCP OFF

4.3 Port forward router
Now you need to port forward all traffic trough one port to the Dreambox ip.
Default port is 12000 but this can be changed in the config (CCcam.cfg).
For more information about port forwarding go here: PortForward.com - Free Help Setting up Your Router or Firewall

5. Software installation Dreambox
Now we need to have the software to make the Dreambox work properly.
First we flash an image to the Dreambox.

5.1 Flash imageThere are different images to choose from and it’s up to you what you prefer.
But let’s chose a PLI image for this guide.
Search this site for the newest image.
When you have downloaded the newest image you need to flash it to your Dreambox.
Instructions can be found here:

7025/7025+
Dream-Multimedia-Tv GmbH

800
Dream-Multimedia-Tv GmbH

600
Dream-Multimedia-Tv GmbH

500+
Dream-Multimedia-Tv GmbH

5.2 Install CCcam
Next step is to install CCcam
Remember that this might change on newer images but the basics will probably be the same.
In the today’s most recent image:
Go to menu/plugins
Click green button
then click softcams and chose CCcam and install.
Remember to change your default cam to CCcam.

6. Software installation (PC)
There aren’t really any software that you have to install but there are some that makes everything easier.

6.1 DNS Updater
This is more or less an must have.
An DNS Updater is a software that constantly checks your public ip and links it to your static ip.
Many ISP have dynamic ip’s which means that you’ll get a public ip that will change once in a while.
It doesn’t mater if you’ll set a static ip in your PC, you’ll still have a public ip that will change.
Therefore you will use a DNS Updater to fix this problem and always link your DNS servername which you will register for to your static ip.
There are a few to chose from but I will recommend two:

DynDNS
Register here
DynDNS Services: DNS, Domain Names, EMail Routing

Download updater here
http://cdn.dyndns.com/windows/DynUpSetup.exe

or if that link does not work you will find it here
DynDNS Support

No-ip
Register for a standard free account here
No-IP™ Free - Free Dynamic DNS - DDNS

Or if you want to see all services look here
Enterprise Managed DNS and Mail Services, 100% DNS Uptime, Domain Registration No-IP™

Download updater here
Download a Free Dynamic DNS Update client for your dynamic IP

6.2 Dreambox Control Center (DCC)
You can use this to edit your CCcam.cfg.
This is pretty easy, just open the program and insert the ip for your router and Dreambox.
You can change the language to English.

6.3 CCcamInfoPHP
This is a software to get statistics and info about your peers and your server.
Now download the latest CCcamInfoPHP from this forum.

6.3.1 Versions 0.8.2 and higher.
Open CCcamInfoPHP_v0.8.2\htdocs\config.php in notpad and change the line you see below to match your server info.
If you haven’t changed your webinterface port or your Dreambox login all you have to do is type in your Dreambox ip.


Code:
$CCCamWebInfo[] = array("192.168.1.xxx","16001","root","dreambox"); // for CCcam webinterface with user and pass

Now open the file located in CCcamInfoPHP_v0.8.2\server\Apache\php.ini
Find this section
Code:
;;;;;;;;;;;;;;;;;;;
; Resource Limits ;
;;;;;;;;;;;;;;;;;;;

and change the line:

max_execution_time = 30 <---- Change this to a higher value like 60
Now you can start CCcamInfoPHP by clicking on CCcamInfoPHP v0.8.2.exe (or CCcamInfoPHP vX.X.X.exe).

6.3.2 Versions before 0.8.2
If you use a windows PC you need to install some server that can handle PHP.
WAMP server is one that does that. Download it here: http://www.en.wampserver.com/
Install WAMPserver in C:\wamp
The zipped file should include a lot of folders and files
extract CCcamInfoPHP to C:\wamp\www\
Now you should find a file in the www folder called config.php.
Open that file in a text editor like notpad.
In that file you will find this lines:

Code:
//examples of server definitions
$CCCamWebInfo[] = array("IP","PORT","USER","PASS"); // for CCcam webinterface with user and pass
$CCCamWebInfo[] = array("IP","PORT");       // for CCcam webinterface with different port than default and without user and pass
$CCCamWebInfo[] = array("IP");
Here you should edit IP to your dreambox ip.
Port to webinterface port.
User and pass to your Dreambox username and pass.
Default Port is 16001
Default username is root
Default pass is dreambox

If you have many peers you might need to change some parameters in
Code:
\wamp\Apache2\bin\php.ini
If you don’t have that file, try this one
Code:
\wamp\bin\apache\apache2.2.6\bin\php.ini
Find this lines in that file (you can open the file in notpad).
Code:
;;;;;;;;;;;;;;;;;;;
; Resource Limits ;
;;;;;;;;;;;;;;;;;;;
max_execution_time = 
max_input_time = 
;max_input_nesting_level = 
memory_limit =
Make sure you have at least this values:
Code:
max_execution_time = 300     ; Maximum execution time of each script, in seconds
max_input_time = 60 ; Maximum amount of time each script may spend parsing request data
;max_input_nesting_level = 64 ; Maximum input variable nesting level
memory_limit = 128M      ; Maximum amount of memory a script may consume (128MB)
Now all you have to do is make sure WAMP server is running and open your web browser and browse to:
http://localhost/index.php
or
http://localhost/somefolder/index.php

7. How to find someone to share with
Now you need to have someone to cardshare with.
If you don’t already have you can try to find someone in the free section here:
http://www.eurocardsharing.com/cc************-free/f199
Remember to read the rules before posting.

When you have found someone to cardshare with you need to exchange C- and Flines.
Let’s go through the basic with Flines and Clines.

8. Flines and Clines the basics
The CCcam.cfg file is located in your Dreambox.
You can access it from your PC with DCC.
FTP to location:
Code:
var/etc
Right click on CCcam.cfg and chose edit.

Fline
The Fline is basically the same as creating a user account on your server.
The Fline consists of a Username and Password
In your config you have a Friend section that is the part where you should add the Flines.

Cline
The Cline is more like a connection string that you give to your peers so that they can connect to your server.
To be able to connect they need to have an account on your server (the Fline).

Here is a basic Fline
F: [username] [password] additional info
F: myfriend abc123 3 0 0 { 0:0:3 }
The part behind the password is privileges and restrictions.
3 0 0 { 0:0:3 }

This user gets all cards at a maximum of 3 hops away from us,
and get's to share them down two further levels beyond his own level.

Here is a basic Cline
C: [server] [port] [Fline username] [Fline password] additional info
C: biocide.******.org 12000 myfriend abc123 no { 0:0:3, 100:3, 100:4 }

no { 0:0:3, 100:3, 100:4 }
no = don’t receives friends emus
{ 0:0:3 = how many hops down you want to receive cards from that server
, 100:3, 100:4 } = here you can block cards from that server

Summary of Clines and Flines

in your config
F: myfriend abc123 3 0 0 { 0:0:3 }
C: the Cline that were sent to you.

In your peers config
F: an Fline that match the Cline that was sent to you
C: your.server.org 12000 myfriend abc123 no { 0:0:3, 100:3, 100:4 }

There are much more you can do in the Cline and Fline but this is the basic that I think everyone should know about.

9. Fake and old cards
There are a lot of fake and old cards that are being shared and slowing down the servers, therefore you need to block all those cards.
Here is a list with old and fake cards:
http://www.eurocardsharing.com/f176/...ormation-20670

10. Block all cards that you don’t want
First of all I want to say that using the method below will block all cards that you don’t choose to receive.
This also means that you will only share the cards that you decide to receive.
Remember that your peers might want cards that you don’t receive because you blocked them, and therefore they can see you as a not so interesting peer.
After every Cline you’ll add:
no { 0:0:1 } This means that you take all cards on hop1.
If you want any card on hop2 you’ll add:
no { 0:0:1, 90f:0:2, b00:0:2, anycard, anycard, anycard }
In this example I chose to get
90f:0 = "Viasat (5E/75E/1W)" on hop2
b00:0 = "Focus(1W) / C+Nordic(1W) / DigiAlb(16E) / MTV(19.2E)" on hop2
The last number is hop:
90f:0:2

11. So you want a big one
If you want to have a bigger server you’ll need a PC as server and Linux as OS.
There are some to chose from and there are already nice guides about this in this forum.

If you want a ClarkConnect server head over to kapzas guide here:
http://www.eurocardsharing.com/f163/...kconnect-43384

Or if you want a Debian server you’ll go to the guide written by CC_share here:
http://www.eurocardsharing.com/f163/...er-cccam-16262

For a Ubuntu server you’ll go to the guide written by Bacteria here:
Installation CCcam server on Ubuntu 6.06

Howto: Building Debian Linux server with CCcam

This how-to will cover the basic installation of Debian linux and getting CCcam up and running on it.

This How-to is still WIP by CC_Share

--Todo--

---------------------------------------

First download the netinstall cd of debian linux
You can download it from the following URL:
Link http://cdimage.debian.org/debian-cd/...86-netinst.iso

This will install the basic debian linux system on you're harddisk.
Boot the computer from the CD you just created.

Just press enter here to start the installation


Select the language you prefer


Select the country you're in. Based on the language it selects a default country


Here you can choose the keyboard layout. Make sure you select the proper layout otherwise installation might prove to be quite tricky.


Set up the hostname of you're server here. I prefer to set up the first part of my DYNDNS account info here.


Here you must enter the domain name. In the example above, you can see i put dyndns.org here


Next up is the partition guide. Here you must choose
Quote:
Guided - Use entire disk



Select the right harddisk. Usually in a stand-alone server, there will just be one entry


Debian will let you choose to have everything in 1 partition, or have seperate partitions for the important directory's. One advantage of having seperate partitions, You cannot fill the root system by accident if you upload a lot to the home directory. Linux will NOT boot correct , if the root filesystem is full


In the overview, You can check to see if all is set up correct before writing the changes to harddisk. Once you press finish, it will show you the next screen if you are really sure .


Once you select yes, It will write the changes to harddisk and format all partitions.


If Debian cannot guess you're timezone by looking at the bios, it will ask you for the timezone


Next you will have to enter the root password. Do not choose an easy to guess password if you want the server to be reachable from the internet. (if you want to use SSH for example to manage the server from work)



Next is setting up an account to use for FTP transfer.


Again, do not use a simple to guess password. This account can also be used for SSH


If you have the option, allways choose a network server.
Make sure you select a fast and stable one.
Usually univercity servers prove to be fast and stable



In the software selection screen, select base system and webserver


One of the last things it needs to know, is where to place the grub bootloader. Usually it is safe to place it on the MBR


Congratulations, You just installed a fresh new DEBIAN server.


As you might have noticed, during installation, debian uses dhcp to aquire an ip adress.
For a cardserver, it's not recommened to have it's IP adress handled by DHCP.
First thing we need to do is remove the DHCP and assign a static IP to the linux server

Assigning static IP
Log in as root with the right password
then type in the following command

Code:
vim /etc/network/interfaces
now remove the following line
Code:
iface eth0 inet dhcp
and replace it with
Code:
auto eth0
iface eth0 inet static
address 192.168.1.225
netmask 255.255.255.0
broadcast 192.168.1.255
gateway 192.168.1.1
These IP adresses might be different for you're situation.
Remember to replace them with the numbers you need.
You can save the file with the following commands
Code:
:wq
Once the file is saved, you can restart the network and check if you're linux server is running with it's new IP adress
Code:
/etc/init.d/networking restart
ifconfig
ifconfig should now look something like this
Quote:
cardserverBackup:/home# ifconfig
eth0 Link encap:Ethernet HWaddr 00:00:00:10:D0:70
inet addr:192.168.1.225 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::250:4ff:fe1d:d27b/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:8931 errors:0 dropped:0 overruns:0 frame:0
TX packets:6028 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:7585683 (7.2 MiB) TX bytes:916823 (895.3 KiB)
Interrupt:10 Base address:0x4000
Installing SSH
Next thing that needs to be done is install a SSH deamon.
This will allow you to log into the cardserver from you're own computer and the server does not require a keyboard and monitor if you want to change something.
Code:
apt-get install openssh-server
Once SSH is installed, you can logout of the server,remove the keyboard and monitor as we don't need it anymore.

Getting Putty
We need to download putty so we can log in with SSH
http://the.earth.li/~sgtatham/putty/.../x86/putty.exe

Remove the CD-ROM drive from the apt-get mirror list:
To make sure the server does not need the CD-ROM anymore to update or install software, we need to remove it from the mirror list of apt-get.
Code:
vim /etc/apt/sources.list
now remove the lines that point to the CD-ROM drive and save the file.
Quote:
deb cdrom:[Debian GNU/Linux 4.0 r0 _Etch_ - Official i386 NETINST Binary-1 20070407-11:29]/ etch contrib main
Update apt-get software list
To make sure, you locally have a good software list available, you have to update the apt-get database
Code:
apt-get update
Installing FTP server
To be able to transfer files between you're computer and the linux server, a FTP server is needed.
During the installation it will ask you one question,. Answer it with "stand-alone"
This will consume a bit more memory but will prevent linux from spawning a new process every time you log in.
Code:
apt-get install proftpd

The server is now installed and all the needed files are in place.
Now it's time to get it ready for CCcam.
First thing we need to do is make 6 directory's and adjust the parameters.
Code:
mkdir /emu
mkdir /emu/cccam
mkdir /emu/script
mkdir /emu/log
mkdir /var/etc
mkdir /var/keys
chmod 777 /emu
chmod 777 /emu/*
chown  /emu
chown  /emu/*
The username started above is the username you created during the installation. This name is going to be used for file transfer.

Startup script for CCcam
To prevent from having to change directory all the time we're gonna place a script on the server so CCcam can be started from any directory on the server.
Code:
vim /emu/script/cccam
Code:
#!/bin/sh
CAMNAME="CCcam Server"
# end
 
# This method starts CCcam
start_cam ()
{
/emu/cccam/CCcam.x86 &
sleep 2
}
# This method stops CCcam
stop_cam ()
{
pkill CCcam.x86
}
case "$1" in
start)
echo "[SCRIPT] $1: $CAMNAME"
start_cam
;;
stop)
echo "[SCRIPT] $1: $CAMNAME"
stop_cam
;;
restart)
echo "Restaring $CAMNAME"
stop_cam
start_cam
;;
*)
"$0" stop
exit 1
;;
esac
exit 0
Code:
chmod 755 /emu/script/cccam
ln /emu/script/cccam /bin/cccam
Now you can simply start, stop or restart CCcam from any directory by simply typing
Code:
cccam start
cccam stop
cccam restart
Upload CCcam
Now use a FTP program to upload CCcam.x86 and CCcam.cfg to /emu/cccam

Making CCcam executable
Use putty again to give CCcam.x86 execution rights
Code:
chmod 755 /emu/cccam/CCcam.x86
Config update script
When you're running a big server, restoring connections can take some time then you change you're config file. I like to do my config changes once a day. I use this script to backup the old config and put the new config in place. This is done at 3am so my peers don't notice it and they don't suffer from a freezing picture every time you make a change.
Code:
vim /emu/script/configupdate.sh
Code:
#!/bin/sh
#Script to process new config and backup old one.
#Script designed and written by CC_Share
SOURCE=/emu/cccam
TARGET=/var/etc
FILE=CCcam.cfg
BACKUPDIR=/var/backup
CONFIGOLD=CCcam.old
if test -f $SOURCE/$FILE ; then
 echo "New Config Present"
 if test -d $BACKUPDIR ; then
  if test -f $BACKUPDIR/$CONFIGOLD ; then
  echo "Removing OLD config file from backup directory"
  rm $BACKUPDIR/$CONFIGOLD
  else
  echo "No OLD config to remove."
  fi
 
                if test -f $BACKUPDIR/$FILE ; then
                echo "Renaming Backup to old config"
                cp $BACKUPDIR/$FILE $BACKUPDIR/$CONFIGOLD
                rm $BACKUPDIR/$FILE
                else
                echo "No Backupfile present yet"
                fi
                if test -f $TARGET/$FILE ; then
                echo "Copying Original config to Backup directory"
                cp $TARGET/$FILE $BACKUPDIR
                rm $TARGET/$FILE
                else
                echo "No Original Config File Present!?!?"
                fi
 else
 echo "Backup directory does not exist."
 echo "making new directory"
 mkdir $BACKUPDIR
                if test -f $TARGET/$FILE ; then
                echo "Copying Original config to Backup directory"
                cp $TARGET/$FILE $BACKUPDIR
                else
                echo "No Original Config File Present!?!?"
                fi
 fi
 echo "Moving New config file to "$TARGET
 cp $SOURCE/$FILE $TARGET
 rm $SOURCE/$FILE
else
echo "No New Config present, Nothing to process"
fi
exit
Code:
chmod 755 /emu/script/configupdate.sh
Putting configupdate in crontab
To make sure the config update script will run at 3 am everynight, we can place it in the crontab.
Code:
cd /etc
vim crontab
and add the following line to it
Code:
00 3 * * * root /emu/script/./configupdate.sh >>/emu/log/configupdate.log 2>&1
This will run the script every day at 3am, and it's output will be writen in /emu/log/configupdate.log so you can check on occasion if all went well.

Putting CCcam in bootsequence

There's only one more thing to do. Add CCcam to the startup so it will start on the next reboot.
Code:
vim /etc/rc.local
and add the following line at the bottom
Code:
/bin/cccam start &
test the config update script created earlier to see if that works
Code:
/emu/script/./configupdate.sh
If it works, you can reboot the server and check if CCcam is running.

How to extract Polsat boxkey from original reciver

Here is link how to extract from polsat approved recivers boxkey to use cards outside they boxes:
Laki Online: FAQ - Tunery satelitarne > Programowanie i naprawa: TUNERY POLSATU

Ps link is in Polish language!