I found few scripts for zabbix apache monitoring and all of them wasn't suitable for me. There is my contribution :). It can do only one request per all of the checks. Source ishere.
python -c "import telnetlib,time;tn = telnetlib.Telnet('127.0.0.1', 10031);tn.write('ppolicyFactory.modules[\'stats\'][0].STAT_DATA\r\n');time.sleep(1);output = [line for line in tn.read_until('}')];print ''.join(output).split()[4][0:-1]"
Second findings are: Python code could be a memory eater. Explanation is here and here. For every string in the list is allocated 80 bytes=2288 MB of RAM for 30,000,000. Solution would be to use smarter data structure in the python (standard int is 24 bytes). With the C we have 2 bytes short int which is little bit less :).
Python sorting file with 30,000,000 numbers took around 2-3GB of RAM (file with numbers was 150 MB). Which is too much memory. Solution is to use special sorting for big files for example something like here or C.
With perl I couldn't sort the 30,000,000 numbers file because of out of memory problems (4GB RAM and 2GB swap).
It'd be interesting to try python with psyco module. Unfortunately the rpm isn't present in the Fedora 14.
Symmetric-key algorithms can be divided into stream ciphers and block ciphers. Stream ciphers encrypt the bytes of the message one at a time, and block ciphers take a number of bytes and encrypt them as a single unit.
A related-key attack can break 256-bit AES with a complexity of 2119, which is faster than brute force but is still infeasible. 192-bit AES can also be defeated in a similar manner, but at a complexity of 2176. 128-bit AES is not affected by this attack. A chosen-plaintext attack can break 8 rounds of 192-bit and 256-bit AES, and 7 rounds of 128-bit AES, although the workload is impractical at 2128 - 2119. (Ferguson et al., 2000). wiki
DES 56 bits Old. DES is now considered to be insecure for many applications.
Triple DES 168 bits (three 56-bit DES keys) Triple DES provides a relatively simple method of increasing the key size of DES to protect against brute force attacks, without requiring a completely new block cipher algorithm. wiki
Serpent 128, 192 or 256 bits The Serpent cipher has not been patented. It is completely in the public domain and can be freely used by anyone. The XSL attack, if effective, would weaken Serpent (though not as much as it would weaken Rijndael, which became AES). However, many cryptanalysts believe that once implementation considerations are taken into account the XSL attack would be more expensive than a brute force attack. The 32 rounds make Serpent have a higher security margin than Rijndael; however, Rijndael with 10 rounds is faster and easier to implement for small blocks. Hence, Rijndael was selected as the winner in the AES competition. wiki
Blowfish Variable key lengthfrom 32 up to 448 bits. recommends using the more recent Twofish algorithm instead. wiki
Advanced Encryption Standard process The Advanced Encryption Standard (AES), the block cipher ratified as a standard by National Institute of Standards and Technology of the United States. Rijndael: 86 positive, 10 negative Serpent : 59 positive, 7 negative Twofish : 31 positive, 21 negative RC6 : 23 positive, 37 negative MARS : 13 positive, 83 negative wiki
Asymmetric key algorithms
Diffie–Hellman key exchange In practice, Diffie–Hellman is not used in this way, with RSA being the dominant public key algorithm. This is largely for historical and commercial reasons, namely that RSA created a Certificate Authority that became Verisign. Diffie–Hellman cannot be used to sign certificates, although the ElGamal and DSA signature algorithms are related to it. wiki
Digital Signature Algorithm (DSA) United States Federal Governmentstandard or FIPS for digital signatures.DSA is covered by U.S. Patent 5,231,668, filed July 26, 1991, and attributed to David W. Kravitz, a former NSA employee. This patent was given to "The United States of America as represented by the Secretary of Commerce, Washington, D.C." and the NIST has made this patent available worldwide.wiki
RSA (Rivest, Shamir and Adleman) It is the first algorithm known to be suitable for signing as well as encryption, and was one of the first great advances in public key cryptography. RSA is widely used in electronic commerce protocols, and is believed to be secure given sufficiently long keys and the use of up-to-date implementations. wiki
Cramer–Shoup cryptosystem It is an extension of the Elgamal cryptosystem. In contrast to Elgamal, which is extremely malleable, Cramer–Shoup adds additional elements to ensure non-malleability even against a resourceful attacker. This non-malleability is achieved through the use of a collision-resistant hash function and additional computations, resulting in a ciphertext which is twice as large as in Elgamal. wiki
Elliptic curve cryptography (ECC) At least one ECC scheme (ECMQV) and some implementation techniques are covered by patents. 128-bit security one needs a curve over F(q), where q 2^256. This can be contrasted with finite-field cryptography (e.g., DSA) which requires 3072-bit public keys and 256-bit private keys, and integer factorization cryptography (e.g., RSA) which requires 3072-bit public and private keys. wiki
U. S. Department of Homeland Security said MD5 "should be considered cryptographically broken and unsuitable for further use,"and most U.S. government applications will be required to move to the SHA-2 family of hash functions by 2010.
is a widely used cryptographic hash function with a 128-bit hash value. As an Internet standard (RFC 1321),Recently, a number of projects have created MD5 rainbow tables which are easily accessible online, and can be used to reverse many MD5 hashes into strings that collide with the original input, usually for the purposes of password cracking. However, if passwords are combined with a salt before the MD5 digest is generated, rainbow tables become much less useful. The use of MD5 in some websites' URLs means that Google can also sometimes function as a limited tool for reverse lookup of MD5 hashes. This technique is also rendered ineffective by the use of a salt. wiki Comparison of cryptographic hash functions
Key size The security of an algorithm cannot exceed its key length (since any algorithm can be cracked by brute force), but it can be smaller. A key should therefore be large enough that a brute force attack (possible against any encryption algorithm) is infeasible – i.e, would take too long to execute. Shannon's work on information theory showed that to achieve so called perfect secrecy, it is necessary for the key length to be at least as large as the message to be transmitted and only used once (this algorithm is called the One-time pad).
As each of these is of a different level of cryptographic complexity, it is usual to have different key sizes for the same level of security, depending upon the algorithm used. For example, the security available with a 1024-bit key using asymmetric RSA is considered approximately equal in security to an 80-bit key in a symmetric algorithm (Source: RSA Security). With a key of length n bits, there are 2n possible keys.
This number grows very rapidly as n increases. Moore's law suggests that computing power doubles roughly every 18 to 24 months, but even this doubling effect leaves the larger symmetric key lengths currently considered acceptably well out of reach. The large number of operations (2128) required to try all possible 128-bit keys is widely considered to be out of reach for conventional digital computing techniques for the foreseeable future.
The Advanced Encryption Standard published in 2001 uses a key size of (at minimum) 128 bits. It also can use keys up to 256 bits (a specification requirement for submissions to the AES contest). 128 bits is currently thought, by many observers, to be sufficient for the foreseeable future for symmetric algorithms of AES's quality. The U.S. Government requires 192 or 256-bit AES keys for highly sensitive data.
As of 2003 RSA Security claims that 1024-bit RSA keys are equivalent in strength to 80-bit symmetric keys, 2048-bit RSA keys to 112-bit symmetric keys and 3072-bit RSA keys to 128-bit symmetric keys. RSA claims that 1024-bit keys are likely to become crackable some time between 2006 and 2010 and that 2048-bit keys are sufficient until 2030. An RSA key length of 3072 bits should be used if security is required beyond 2030. NIST key management guidelines further suggest that 15360-bit RSA keys are equivalent in strength to 256-bit symmetric keys.
One of the asymmetric algorithm types, elliptic curve cryptography, or ECC, appears to be secure with shorter keys than those needed by other asymmetric key algorithms. NIST guidelines state that ECC keys should be twice the length of equivalent strength symmetric key algorithms. So, for example, a 224-bit ECC key would have roughly the same strength as a 112-bit symmetric key. These estimates assume no major breakthroughs in solving the underlying mathematical problems that ECC is based on. A message encrypted with an elliptic key algorithm using a 109-bit long key has been broken by brute force.
The amount of time required to break a 128-bit key is also daunting. Each of the 2128 (340,282,366,920,938,463,463,374,607,431,768,211,456) possibilities must be checked. A device that could check a billion billion keys (1018) per second would still require about 1013 years to exhaust the key space. This is a thousand times longer than the age of the universe, which is about 13,000,000,000 (1.3×1010) years.
AES permits the use of 256-bit keys. Breaking a symmetric 256-bit key by brute force requires 2128 times more computational power than a 128-bit key. A device that could check a billion billion (1018) AES keys per second would require about 3×1051 years to exhaust the 256-bit key space. An underlying assumption of this analysis is that the complete keyspace is used to generate keys, something that relies on an effective random number generator. wiki
modprobe.conf alias bond0 bonding options bond0 miimon=80 mode=1 downdelay=200 updelay=200
mode=0 (balance-rr) Round-robin policy: Transmit packets in sequential order from the first available slave through the last. This mode provides load balancing and fault tolerance.
mode=1 (active-backup) Active-backup policy: Only one slave in the bond is active. A different slave becomes active if, and only if, the active slave fails. The bond's MAC address is externally visible on only one port (network adapter) to avoid confusing the switch. This mode provides fault tolerance. The primary option affects the behavior of this mode.
mode=2 (balance-xor) XOR policy: Transmit based on [(source MAC address XOR'd with destination MAC address) modulo slave count]. This selects the same slave for each destination MAC address. This mode provides load balancing and fault tolerance.
mode=3 (broadcast) Broadcast policy: transmits everything on all slave interfaces. This mode provides fault tolerance.
mode=4 (802.3ad) IEEE 802.3ad Dynamic link aggregation. Creates aggregation groups that share the same speed and duplex settings. Utilizes all slaves in the active aggregator according to the 802.3ad specification.
Pre-requisites: 1. Ethtool support in the base drivers for retrieving the speed and duplex of each slave. 2. A switch that supports IEEE 802.3ad Dynamic link aggregation. Most switches will require some type of configuration to enable 802.3ad mode.
mode=5 (balance-tlb) Adaptive transmit load balancing: channel bonding that does not require any special switch support. The outgoing traffic is distributed according to the current load (computed relative to the speed) on each slave. Incoming traffic is received by the current slave. If the receiving slave fails, another slave takes over the MAC address of the failed receiving slave.
Prerequisite: Ethtool support in the base drivers for retrieving the speed of each slave.
mode=6 (balance-alb) Adaptive load balancing: includes balance-tlb plus receive load balancing (rlb) for IPV4 traffic, and does not require any special switch support. The receive load balancing is achieved by ARP negotiation. The bonding driver intercepts the ARP Replies sent by the local system on their way out and overwrites the source hardware address with the unique hardware address of one of the slaves in the bond such that different peers use different hardware addresses for the server.
Jediné co se v targeted používá je types_t(Type Enforcement) a user_u(velice omezeně)
user_u práva /usr/sbin/semanage login -l Ukáže mapování uživatelů na SELinux
unconfined_u .. nevztahuje se na něj SELinux (takto spuštěné procesy se chovají stejně jako bez SELinuxu)
system_u .. standardní systémový uživatel (řídí se dle SELinux pravidel)
type_t práva Vše co končí na _t patří do Type. Práva se dědí dle adresáře.
httpd_t .. základní jméno
httpd_sys_content_t .. static web
httpd_sys_script_exec_t .. skripty, které může Apache spouštět
httpd_sys_content_rw_t .. soubory do, kterých může zapisovat pouze httpd_sys_script_exec_t
httpd_sys_content_ra_t .. pouze přidávat
Nastavení se dají zjistit například nainstalováním SELinux devel
yum install selinux-policy-devel.noarch
A průzkumem jednotlivých konfiguráků v
/usr/share/selinux/devel/include
Pro jednotlivé adresáře jsou práva zadaná v
/etc/selinux/targeted/contexts/files/
SELinux transition Některá pravidla slouží k tomu, aby měnila type_t spouštěných aplikací.
Například toto initrc_t, named_exec_t, named_t nám říká, pokud proces initrc_t spouští soubor named_exec_t mají přejít práva z initrc_t na named_t. Normálně to co spustí proces initrc_t běží s právy initrc_t.
Příklad předávání práv:
Změna policy za běhu
Výpis všech nestavení, které se dají měnit za běhu getsebool -a
Nastavení požadované hodnoty setsebool -P virt_use_nfs [1|0]
Konfiguráky /etc/selinux
Logy /var/log/audit/audit.log
Zapnutí SELinuxu Pro změnu z disable na permissive nebo enforcing je potřeba restartovat počítač. Změna z permissive na enforcing a obráceně je možná za chodu.
Změnu lze provést zde /etc/selinux/config
Změna za chodu (trvá pouze do restartu jinak se musí zapsat do konfiguráku)
Permissive na Enforcing echo "1" > /selinux/enforce nebo setenforce 0
Enforcig na Permissive echo "0" > /selinux/enforce nebo setenforce 1
Ověření stavu SELinuxu sestatus
SELinux změněné příkazy ls -Z, id -Z, ps auxZ, lsof -Z, find / -context
Moduly SELinuxu Vypsání všech modulů semodule -l
Změna SELinux práv na souborech Krátkodobá (do restartu) chcon -t type file-name
Trvalá (zapíše do souboru /etc/selinux/targeted/contexts/files/file_contexts.local) Soubor /usr/sbin/semanage fcontext -a -t samba_share_t /etc/file1 Adresář /usr/sbin/semanage fcontext -a -t httpd_sys_content_t "/web(/.*)?"
Obnovení práv podle souborů v /etc/selinux/targeted/contexts/files/ /sbin/restorecon -R -v /adresar/
Práce se soubory Kopírování Zachování práv cp -Z co kam Přesun Vždy si zachovává práva co měl. Kontrola práv Udělá kontrolu zda jsou nastavena práva dle definic. /usr/sbin/matchpathcon -V Cesta
Snaha o vytvoreni jedoducheho vyskakovaciho okna (na vareni uplne idalni vec :)) ). Uz jsem si to musel zapsat. Zjistovani jak to funguje mi zase sezralo hodinu :(. echo 'export DISPLAY=":0.0";/usr/bin/zenity --info --text "Nejaky Vtipny Text"' | at now+1min
Koupil jsem si prilis komplikovanou mys. 11 tlacitek celkem. Bohuzel funkcnost v linuxu je takova zvlastni. Novy evdev driver vsechna tlacitka pozna a umozni vyuzivat, ale s ostatnimi palikacemi je to trosku slozitejsi (naprosto nechapu kde je zakopany pes).K vyreseni tohoto problemu tu mame xev, xbindkeys, xmacroplay.
xev..ukaze po zmacknuti kod klavesy a vsechny veci s tim souvesijici (napriklad zda je klavesa detekovana) xbindkeys..umozni po stisknuti urcite kombinace klaves spustit libovolny program xmacroplay..umoznuje poslat klavesu nebo kombinaci klaves xservru
Spusteni xbindkeys v povidacim modu xbindkeys -n -v
Muj .xbindkeysrc zatim spis prvni pokus.
# Control + mouse button 1 starts an xterm # "xterm" # Control + b:13
# Mappings for keys for MX Revo # b:1 - left mouse button # b:2 - left and right mouse button together # b:3 - right mouse button # b:4 - mouse wheel up # b:5 - mouse wheel down # b:6 - mouse wheel left # b:7 - mouse wheel right # b:8 - back button # b:9 - forward button # b:10 - -none- # b:11 - -none- # b:12 - -none- # b:13 - media wheel up # b:14 - -none- # b:15 - media wheel down # b:16 - media wheel press # b:17 - -none-
Rozsireni stavajiciho oddilu o novy disk Muzme nejdriv pouzit fdisk a vytvorit partiton (neni nutnost) Incializujeme disk pro LVM. pvcreate /dev/sdb1 (pvremove /dev/sdb1 nam oddil odstrani) pvdisplay nam ukaze vsechny inicializovane disky.
Pridame disk do Grupy. vgextend VolGroup00 /dev/sdb1
Ted mame ve skupine dva disky sda a sdb. Pokud by jsme chteli jeden disk odstranit muzme pouzit Presuneme data z sdb1 na sda1. vgmove /dev/sdb1 /dev/sda1 Odstranime disk ze skupiny. vgreduce VolGroup00 /dev/sdb1 Zrusime inicializaci LVM na disku. pvremove /dev/sdb1
Pro rozsireni skupiny pouzijeme prikaz: lvextend -l +100%PVS /dev/VolGroup00/LogVol00 /dev/sdb1 rozsirujeme o 100% velikosti /dev/sdb1
Odebrani disku
nejdrive zmensime oddil o pozadovanou velikost
nejdrive zmensime LV
odstranime disk z VG
odstranime z disku PV
ad.1 resize2fs /dev/VolGroup00/LogVol00 2048M Tento bod musime dodrzet jinak si lehce zkorumpuje disk.Jde normalne pripojit, ale hlasi spatnou velikost. Reseni je znovu VG rozsirit. Bohuzel resize smerem dolu jde pouze pri odmontovanem disku.
ad 2. Zjistime mnozstvi alokovanych PE (physical extent(nejmesi mozna adresovatelna jednotka LVM)) jednotek. lvreduce -l -31 /dev/VolGroup00/LogVol00
ad 3. Odstranime disk z VG. vgreduce VolGroup00 /dev/sdb1
Problem Situace: Jak opravit situaci kdy jeden z linarne namapovanych disku prestane fyzicky existovat. Je treba ho odebrat z LVM a upravit velikost ext3 oddilu.
Odebrat disk z VG grupy
Seznam prikazu lvmdiskscan - ukaze vsechna zarizeni pouzitelna pro LVM pvs,lvs,vgs - informace o PV, LV,VG pvscan, lvscna, vgscan - prohleda disky pro ... pv(lv,vg)display - ukaze atributy ... vgchange - zmeni attributy volume grupy vgcfgbackup - zaloha LVM metadat
Otazka zni: kde se co zapisuje pri ssh prihlaseni u Fedory 10(asi to bude stejne pro RH obecne).
Pro zjisteni pouzijeme aide tak aby sledovala cely fs krome /dev a /proc .
spustime aide -C (vytvori nam referencni soubor)
prihlasime se a napiseme par prikazu
aide -i > aide.diff
Zapsane soubory jsou tyto:
/var/log/btmp
/var/log/wtmp(utmp)
/var/log/lastlog
/var/log/secure
/var/log/.bash_history
ad 1. zaznamenava spatne loginy - binarni soubor. lastb pro zobrazeni.
ad 2. zaznamenava vsechny loginy - binarni soubor. last pro zobrazeni
Oba zaznemenavaji cas a IP adresu
ad 3. textovy soubor kde je zapis posledniho prihlaseni pro vsechny uzivatele. lastlog pro zobrazeni
ad 4. textovy soubor se vsim moznym co se tyka bezpecnosti (zaznamenany spatny pokus o nalogovani)
ad 5. textovy soubor s historii prikazu.
who Shows a listing of currently logged-in users. w Shows who is logged on and what they are doing. last Shows a list of last logged-in users, including login time, logout time, login IP address, etc. lastb Same as last, except that by default it shows a log of the file /var/log/btmp, which contains all the bad login attempts. lastlog This command reports data maintained in /var/log/lastlog, which is a record of the last time a user logged in. ac Prints out the connect time in hours on a per-user basis or daily basis etc. This command reads /var/log/wtmp. dump-utmp Converts raw data from /var/run/utmp or /var/log/wtmp into ASCII-parsable format.
V /etc/sysconfig/network-scripts/ vytvorime ifcfg-wlan0 s DEVICE=wlan0
dhclient wlan0
a nebo na stalo V /etc/sysconfig/network-scripts/ vytvorime ifcfg-wlan0 s DEVICE=wlan0 IPADDR=nejaka IP NETMASK=255.255.255.0 ONBOOT=yes BOOTPROTO=static(dhcp) TYPE=Wireless MODE=Managed ESSID=homenet KEY=967136deac(jsem zadat password asi)
Ukol: Naistalovat Linux z jineho linuxu a spustit ho pomoci kvm. Kroky:
Vytvorit obraz
Naformatovat obraz na dve casti (/,tmp)
Nainstalovat system
Spustit
Ad 1. Vytvoreni 4GB obrazu. dd if=/dev/zero of=/home/slune/Image/gentoo.img bs=1M count=4096 . Ad 2. Nejjednodussi zpusob je pouzit mkfs.ext3 /home/slune/Images/gentoo.img. Tim sice vznikne pripojitelny a zapisovatelny obraz, ale pro fdisk naprosto nepozitelny (vyzaduje block device). Zpusob jako toto obejit vede zrejme losetup /dev/loop1 /home/slune/Images/gentoo.img a fdisk /dev/loop1. Navody zde a zde. Po vytvoreni struktury fdiskem zkoukneme jak nam to vypada
fdisk -ul /dev/loop1
Disk /dev/loop1: 4294 MB, 4294967296 bytes 255 heads, 63 sectors/track, 522 cylinders, total 8388608 sectors Units = sectors of 1 * 512 = 512 bytes Disk identifier: 0x2cdb556f
Device Boot Start End Blocks Id System /dev/loop1p1 * 63 6313544 3156741 83 Linux /dev/loop1p2 6313545 8385929 1036192+ 83 Linux
Aby jsme mohli disky naformatovat musime je nejdriv pripojit.
Pozn: Prvni disk se ale pripoji s velikosti celeho obrazu. Zrejme je potreba urcit i horni velikost. Nejak takhle losetup -o 32256 --sizelimit 3232502272 /dev/loop1 /dev/loop0. Pokud jsem to neudelal mkfs mi pak "spatne" naformatoval system (nastavil spatnou velikost disku).
Pozn: Gentoo potrebuje pro instalaci velke mnozstvi inodu (vice nez 200 000) pro instalaci na mensi disky je potrebamkfs.ext3 -N (velke cislo) /dev/loop2.
Pozn: Je potreba stahnout portage a satge3 viz. link a rozbalit je. Portage se musi rozbalit do adresare usr. (Neco takoveho tar xvjf /mnt/gentoo/portage-latest.tar.bz2 -C /mnt/gentoo/usr)
Dalsi krok je pripojeni systemovych adresaru mount -t proc none /mnt/gentoo/proc/ mount -o bind /dev /mnt/gentoo/dev/
Tady bych to chtel vic prozkoumat
Chroot do noveho prostredi chroot /mnt/gentoo /bin/bash env-update source /etc/profile # zmena promptu export PS1="(chroot) $PS1"
Pokracovani stahneme si nejaky kernel(treba vanilla) rozbalime do /usr/src/. Udalame link ln -s /usr/src/neco /usr/src/linux (nebo jsme liny a emergneme celou tu potvoru emerge vanilla-sources). A ted troska srandy cd /usr/src/linux make menuconfig
Zkusime nastavit vse co je potreba coz se nemuze nikdy na poprve povest.
Instalace zprasenho kernelu make && make modules_install
Poznamka pokud kompilujeme x86 na x64 pak je trebamake ARCH=i386
Tento postup opakujem tak dlouho dokud nam nenabehne system (dost dlouho)
Insalace grubu
Grub potrebuje k zivotu nekolik souboru.
stage1
stage2
grub.conf
bzImage kernelu
Stage1 a Stage2 jsou umisteny ve Fedore tady /usr/share/grub/ a nakopirujeme je do /boot/grub/ grub.conf muze vypadat treba takto