{"id":417,"date":"2015-10-19T21:13:00","date_gmt":"2015-10-19T13:13:00","guid":{"rendered":"http:\/\/note.systw.net\/note\/?p=417"},"modified":"2024-02-17T20:34:25","modified_gmt":"2024-02-17T12:34:25","slug":"linux-security","status":"publish","type":"post","link":"https:\/\/systw.net\/note\/archives\/417","title":{"rendered":"Linux Security"},"content":{"rendered":"\n<p>linux security<\/p>\n\n\n\n<p><strong>why is linux hacked<\/strong><br>1linux is widely used on a large number of servers in the word,making it a &#8216;de facto&#8217; backbone<br>2since application source code is a available,it is easy to find out the vulnerabilities of the system<br>3many application on linux are installed by default so they are more vulnerable to attacks<\/p>\n\n\n\n<p><strong>linux vulnerabilities<\/strong><br>\u5e38\u898b\u7684\u6709:<br>bind<br>lxr(linux cross-referencing vulnerability)<br>utli-linux vulnerability<br>linux kernel capabiliy vulnerability<br>ps:\u57f7\u884cexecve() system call\u6709local root exploit\u6642,\u89e3\u6c7a\u65b9\u6cd5\u70baupgrade kernel<\/p>\n\n\n\n<p>&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;<\/p>\n\n\n\n<p><strong>chrooting<\/strong><br>run command or interactive shell with special root directory<br>ex:chroot \/usr\/local\/tester \/bin\/testscript<br>\u901a\u5e38\u5728\u6839\u76ee\u9304\u4e0b\u6709\u975e\u5e38\u591a\u6771\u897f\uff0c\u5305\u542b\u5f88\u591a\u7684\u8a2d\u5b9a\u6a94\u3001\u51fd\u5f0f\u5eab\uff0c\u6771\u897f\u8d8a\u591a\u8d8a\u6709\u53ef\u80fd\u88ab\u6293\u5230\u7cfb\u7d71\u4e0a\u7684\u6f0f\u6d1e\uff0c\u4f7f\u7528\u8005\u4e5f\u53ef\u4ee5\u67e5\u770b\u5f88\u591a\u7cfb\u7d71\u4e0a\u7684\u8a2d\u5b9a\u6a94\uff0c\u82e5\u4e0d\u60f3\u8b93\u4f7f\u7528\u8005\u770b\u5230\u90a3\u9ebc\u591a\u7684\u6771\u897f\uff0c\u6700\u597d\u7684\u505a\u6cd5\u5c31\u662f\u7528chroot\u628a\u4ed6\u9396\u8d77\u4f86<br>chroot\u4e3b\u8981\u5c31\u662f\u53e6\u5916\u518d\u6253\u9020\u4e00\u500broot\u74b0\u5883\u63d0\u4f9b\u7d66\u4f7f\u7528\u8005\uff0c\u4f7f\u7528\u8005\u80fd\u4f7f\u7528\u4ec0\u9ebccommand\u90fd\u662f\u53d7\u63a7\u5236\u7684\uff0c\u53ea\u8981\u7d66\u8db3\u5920\u7528\u7684\u51fd\u5f0f\u5eab\u5c31\u5920\u4e86\uff0c\u66f4\u4e0d\u7528\u8aaa\u4f7f\u7528\u8005\u80fd\u770b\u5230\u4ec0\u9ebc\u7cfb\u7d71\u7684\u8a2d\u5b9a\u6a94\u56c9\uff01<\/p>\n\n\n\n<p>\u597d\u8655<br>\u9650\u5236\u88abCHROOT\u7684\u4f7f\u7528\u8005\u6240\u80fd\u57f7\u884c\u7684\u7a0b\u5f0f\uff0c\u5982SetUid\u7684\u7a0b\u5f0f\uff0c\u6216\u662f\u6703\u9020\u6210 Load \u7684 Compiler\u7b49\u7b49\u3002<br>\u9632\u6b62\u4f7f\u7528\u8005\u5b58\u53d6\u67d0\u4e9b\u7279\u5b9a\u6a94\u6848\uff0c\u5982\/etc\/passwd\u3002<br>\u9632\u6b62\u5165\u4fb5\u8005\/bin\/rm -rf \/\u3002<br>\u63d0\u4f9bGuest\u670d\u52d9\u4ee5\u53ca\u8655\u7f70\u4e0d\u4e56\u7684\u4f7f\u7528\u8005\u3002<br>\u589e\u9032\u7cfb\u7d71\u7684\u5b89\u5168\u3002<\/p>\n\n\n\n<p>\u76f8\u95dctool<br>addjailsw:helps automate the creation of jail chroots<\/p>\n\n\n\n<p>&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;<\/p>\n\n\n\n<p>way to prevent hacking<\/p>\n\n\n\n<p><strong>1keep programs up-to-date<\/strong>:primary way<\/p>\n\n\n\n<p><strong>2\u95dc\u9589\u6c92\u5728\u7528\u7684suid program<\/strong><br>\u82e5\u8a2d\u5b9asuid\u7684program\u88abbuffer overflow,&#8230;\u7b49\u653b\u64ca,\u5247attacker\u53ef\u62ff\u5230root\u6b0a\u9650<br>ps:<br>\u5217\u51fa\u7cfb\u7d71\u4e0a\u6240\u6709\u8a2d\u5b9asuid\u7684\u6b0a\u9650<br>find \/ -perm -04000 -type f -ls<\/p>\n\n\n\n<p><strong>3\u4f7f\u7528stackguard,libsafe,openwall project<\/strong><br>stackguard:a compiler that hardens programs against stack smashing attack<br>libsafe:a dynamically loadable library that checks all calls made to vulnerable library functions<br>openwall project&#8217;s non-exec stack kernel patch:a collection of security features for the linux kernel that makes the stack non-executable<\/p>\n\n\n\n<p>&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.<\/p>\n\n\n\n<p>tool:<br>scanning network:netcat,strobe,nmap<br>scanning tool:nessus<\/p>\n\n\n\n<p>port scan detection tools\u6709\u4ee5\u4e0b:<br>klaxon<br>scanlogd<br>portsentry:\u53ef\u7acb\u5373\u5075\u6e2c\u4e26\u5c01\u9396\u610f\u5716\u4fb5\u5165\u8005 (\u6383 port\u3001\u5617\u8a66\u9023\u5165\u7279\u5b9a\u57e0\u53e3) \u7684\u884c\u52d5<br>lids<\/p>\n\n\n\n<p>\u5bc6\u78bc\u7834\u89e3tools<br>john the ripper<br>slurpie<br>ps<br>linux\u5bc6\u78bc\u5728\/etc\/shadow<\/p>\n\n\n\n<p>&#8230;&#8230;&#8230;&#8230;&#8230;.<\/p>\n\n\n\n<p><strong>\u6e05\u9664track<\/strong><br>ex:<br>\u6e05\u9664\/dev\/hda0<br>dd if=\/dev\/random of=\/dev\/hda0<br>or<br>dd if=\/dev\/zero of=\/dev\/hda0<\/p>\n\n\n\n<p>ps:\/dev\/zero \u6703\u4e0d\u65b7\u7522\u751fnull<\/p>\n\n\n\n<p>knoppix erase tool<br>wipe&nbsp;: wipe a partition securely. good for prep&#8217;ing a partition for dd<br>ex:wipe -fik \/dev\/hda1<\/p>\n\n\n\n<p>&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;<\/p>\n\n\n\n<p><strong>\u57fa\u672clinux\u4fdd\u8b77<\/strong><br>\u900f\u904e\/etc\/sysctl.conf\u4fee\u6539kernel\u53c3\u6578<br>net\/ipv4\/conf\/all\/rp_filter=1<br>net\/ipv4\/conf\/all\/log_martians=1<br>net\/ipv4\/conf\/all\/send_redirects=0<br>net\/ipv4\/conf\/all\/accept_source_route=0<br>net\/ipv4\/conf\/all\/acept_redirects=0<br>net\/ipv4\/tcp_syncookies=1<br>net\/ipv4\/icmp_echo_ignore_broadcasts=1<br>net\/ipv4\/ip_forward=1<\/p>\n\n\n\n<p>\u5b89\u5168\u5206\u6790\u5de5\u5177<br>sara(security auditor&#8217;s research assistant):\u65e9\u671fscan tool<br>netcat: \u9810\u8a2d\u5b89\u88dd\u6c92\u6709-e\u529f\u80fd<br>tcpdump<br>snort<br>saint:for unix\/linux<br>wireshark<br>abacus port sentry<br>dsniff collection:\u5c08\u9580\u7528sniffer\u6536\u96c6\u5bc6\u78bc<br>hping2:\u53ef\u7522\u751f\u5c01\u5305<br>sniffit<br>nemesis<br>lsof(list open files):lists open files for running unix\/linux process<br>iptraf:\u53ef\u5373\u6642\u770b\u6d41\u91cf<br>lids(linux ids)<br>tcp wrappers<\/p>\n\n\n\n<p><strong>LSoF<\/strong><br>\u9019\u662f\u4e00\u6b3eUnix\u5e73\u53f0\u4e0a\u7684\u8a3a\u65b7\u548c\u7814\u7a76\u5de5\u5177\uff0c\u5b83\u53ef\u4ee5\u5217\u8209\u7576\u524d\u6240\u6709\u9032\u7a0b\u6253\u958b\u7684\u6587\u4ef6\u4fe1\u606f\u3002<br>\u5b83\u4e5f\u53ef\u4ee5\u5217\u8209\u6240\u6709\u9032\u7a0b\u6253\u958b\u7684\u901a\u8a0a socket\uff08communications sockets\uff09\u3002<br>Windows\u5e73\u53f0\u4e0a\u985e\u4f3c\u7684\u5de5\u5177\u6709Sysinternals\u3002<\/p>\n\n\n\n<p>\u653b\u64catool<br>hunt:session hijacking tool<\/p>\n\n\n\n<p><strong>LKM(linux loadable kernel modules)<\/strong><br>LKMs are loadable kernel modules used by the linux kernel to expand its functionality<br>advantage:<br>\u3000they can be loaded dynamically<br>\u3000there must be no recompilation of the whole kernel<br>\u7528\u9014:<br>\u3000specific device drivers ,ex:soundcards<\/p>\n\n\n\n<p>&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;<\/p>\n\n\n\n<p><strong>linux rootkits<\/strong><br>\u82e5\u88ab\u88dd rootkis\u5f88\u96e3\u88ab\u627e\u51fa\u4f86,\u56e0\u70barootkis\u53ef\u4ee5\u85cf\u7684\u5730\u65b9\u592a\u591a<br>ex:<br>\u63db\u6389ls,\u5247\u7121\u6cd5\u7528ls\u627e\u5230\u8a72rootkis<br>\u63db\u6389ps,\u5247\u7121\u6cd5\u7528ps\u627e\u5230\u554f\u984cprocess<\/p>\n\n\n\n<p>rootkits tools<br>IRK4(linux rootkits IV)<br>knark,torn:\u8f03\u6709\u540d\u7684rootkis<br>tuxit,adore,ramen<br>beastkit<\/p>\n\n\n\n<p><strong>\u9632\u5236rootkits tools<\/strong><br>chkrootkit:to check for the presence of rootkits,\u4e0d\u904e\u901a\u5e38\u90fd\u6293\u4e0d\u5230<br>tripwire<br>bastille linux<br>lids<br>dtk<br>rkdet<br>rootkit hunter<br>carbonite<br>rescan<br>saint jude<\/p>\n\n\n\n<p>&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;<\/p>\n\n\n\n<p><strong>application security:<\/strong><br>whisker:cgi vulnerability scanner,\u4f46\u6548\u679c\u6709\u9650<br>flawfinder<br>stackguard: \u907f\u514dbuffer overflow<br>libsafe:\u907f\u514dbuffer overflow<br>AIDE(advanced intrusion detection environment):a free replacement for tripwire<\/p>\n\n\n\n<p>security testing tool:<br>nmap<br>lsof<br>netcat<br>hping2<br>nemesis<\/p>\n\n\n\n<p>encryption tool:<br>stunnel<br>openssh<br>gnupg<\/p>\n\n\n\n<p>log and traffic monitors tool:<br>mrtg<br>swatch<br>timbersee<br>logsurf<br>tcp wrappers<br>iplog<br>iptraf<br>ntop<\/p>\n\n\n\n<p>security auditing tool:<br>LSAT<\/p>\n\n\n\n<p>&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;<\/p>\n\n\n\n<p><strong>linux security countermeasures:<\/strong><br>check user account with null password in \/etc\/shadow<br>close the door first by denying access from network by default<br>stop all unused services<br>check system log in \/var\/log\/ ,\/var\/log\/secure<br>checking the errate(bug fixes)<br>ex:www.redhat.com\/support\/errate<br>update linux system regularly<\/p>\n\n\n\n<p>&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;<br>&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;<\/p>\n\n\n\n<p>adduser<br>Usage: useradd [options] LOGIN<br>Options:<br>-b, &#8211;base-dir BASE_DIR base directory for the new user account home directory<br>-c, &#8211;comment COMMENT set the GECOS field for the new user account<br>-d, &#8211;home-dir HOME_DIR home directory for the new user account<br>-D, &#8211;defaults print or save modified default useradd configuration<br>-e, &#8211;expiredate EXPIRE_DATE set account expiration date to EXPIRE_DATE<br>-f, &#8211;inactive INACTIVE set password inactive after expiration to INACTIVE<br>-g, &#8211;gid GROUP force use GROUP for the new user account<br>-G, &#8211;groups GROUPS list of supplementary groups for the new user account<br>-h, &#8211;help display this help message and exit<br>-k, &#8211;skel SKEL_DIR specify an alternative skel directory<br>-K, &#8211;key KEY=VALUE overrides \/etc\/login.defs defaults<br>-m, &#8211;create-home create home directory for the new user account<br>-l, do not add user to lastlog database file<br>-M, do not create user&#8217;s home directory(overrides \/etc\/login.defs)<br>-r, create system account<br>-o, &#8211;non-unique allow create user with duplicate (non-unique) UID<br>-p, &#8211;password PASSWORD use encrypted password for the new user account<br>-s, &#8211;shell SHELL the login shell for the new user account<br>-u, &#8211;uid UID force use the UID for the new user account<br>-Z, &#8211;selinux-user SEUSER use a specific SEUSER for the SELinux user mapping<\/p>\n\n\n\n<p><br>passwd<br>Usage: passwd [OPTION&#8230;]<br>-k, &#8211;keep-tokens keep non-expired authentication tokens<br>-d, &#8211;delete delete the password for the named account (root only)<br>-l, &#8211;lock lock the named account (root only)<br>-u, &#8211;unlock unlock the named account (root only)<br>-f, &#8211;force force operation<br>-x, &#8211;maximum=DAYS maximum password lifetime (root only)<br>-n, &#8211;minimum=DAYS minimum password lifetime (root only)<br>-w, &#8211;warning=DAYS number of days warning users receives before password expiration (root only)<br>-i, &#8211;inactive=DAYS number of days after password expiration when an account becomes disabled (root only)<br>-S, &#8211;status report password status on the named account (root only)<br>&#8211;stdin read new tokens from stdin (root only)<\/p>\n\n\n\n<p><br>\u6539\u8b8a\u6a94\u6848\u6642\u9593<br>touch<br>Usage: touch [OPTION]&#8230; FILE&#8230;<br>Update the access and modification times of each FILE to the current time.<br>Mandatory arguments to long options are mandatory for short options too.<br>-a change only the access time<br>-B SEC, &#8211;backward=SEC date back SEC seconds<br>-c, &#8211;no-create do not create any files<br>-d, &#8211;date=STRING parse STRING and use it instead of current time<br>-F SEC, &#8211;forward=SEC date forward SEC seconds<br>-f (ignored)<br>-m change only the modification time<br>-r, &#8211;reference=FILE use this file&#8217;s times instead of current time<br>-t STAMP use [[CC]YY]MMDDhhmm[.ss] instead of current time<br>&#8211;time=WORD set time given by WORD:access atime use (same as -a),modify mtime (same as -m)<br>&#8211;help display this help and exit<br>&#8211;version output version information and exit<br>Note that the -d and -t options accept different time-date formats.<br>ex:<br>\u5c07\/etc\/passwd\u7684 access time\u548cmodification time\u8a2d\u5b9a\u6210\u548c\/etc\/test\u4e00\u6a23<br>touch -acmr \/etc\/test \/etc\/passwd<\/p>\n","protected":false},"excerpt":{"rendered":"<p>linux security why is linux ha &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"","fifu_image_alt":"","_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[39],"tags":[],"class_list":["post-417","post","type-post","status-publish","format-standard","hentry","category-concept"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/posts\/417","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/comments?post=417"}],"version-history":[{"count":0,"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/posts\/417\/revisions"}],"wp:attachment":[{"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/media?parent=417"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/categories?post=417"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/tags?post=417"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}