<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SpaLinux.com &#187; Security</title>
	<atom:link href="http://spalinux.com/category/security/feed" rel="self" type="application/rss+xml" />
	<link>http://spalinux.com</link>
	<description>Resources for Relaxing Linux System Administrators</description>
	<lastBuildDate>Sat, 21 Jan 2012 16:07:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>เก็บข้อมูลการใช้เว็บผ่าน Linux Router ด้วย Squid Transparent Proxy</title>
		<link>http://spalinux.com/2011/11/how-to-log-web-traffic-via-linux-router-using-squid-transparent-proxy</link>
		<comments>http://spalinux.com/2011/11/how-to-log-web-traffic-via-linux-router-using-squid-transparent-proxy#comments</comments>
		<pubDate>Fri, 25 Nov 2011 17:44:17 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Networking]]></category>
		<category><![CDATA[Proxy]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[router]]></category>
		<category><![CDATA[Squid]]></category>
		<category><![CDATA[Transparent Proxy]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=1519</guid>
		<description><![CDATA[ด้วยกฎหมาย พรบ. ที่เริ่มมีผลบังคับ ให้เก็บข้อมูลการใช้เว็บอินเตอร์เน็ต ว่าเป็นใครใช้ เข้าเว็บไหน เมื่อไร ถ้าเป็นเครื่องที่เราสามารถดูแลได้ วิธีหนึ่งที่ทำได้คือ คอนฟิก Proxy ใน ฺBrowser ของแต่ละเครื่องที่จะใช้อินเตอร์เน็ต ชี้ไปยัง Proxy Server ที่ทำหน้าที่เก็บข้อมูลการใช้งาน แต่ถ้าเราไม่สามารถควบคุมดูแลได้ หรือเครื่องที่ใช้งานมีการเปลี่ยนแปลงตลอดเวลา เช่นให้บริการอินเตอร์เน็ต สำหรับผู้มาติดต่องาน ถ้าเป็นแบบนี้ แนะนำให้คอนฟิก Transparent Proxy บน Linux Router เพื่อให้ทำหน้าที่เก็บข้อมูลการใช้เว็บโดยอัตโนมัติ ระบบทดสอบ Linux Router ติดตั้ง Squid มีพอร์ต LAN สองพอร์ต eth0, eth1 เครื่องผู้ใช้งานทั้งหมดต่อพอร์ต eth0 ของ Linux Router พอร์ต eth1 ของ Linux Router ต่อไปยังอินเตอร์เน็ต Redirect Web Traffic ให้เข้าไปใน Proxy [...]]]></description>
			<content:encoded><![CDATA[<p>ด้วยกฎหมาย พรบ. ที่เริ่มมีผลบังคับ ให้เก็บข้อมูลการใช้เว็บอินเตอร์เน็ต ว่าเป็นใครใช้ เข้าเว็บไหน เมื่อไร</p>
<p>ถ้าเป็นเครื่องที่เราสามารถดูแลได้ วิธีหนึ่งที่ทำได้คือ คอนฟิก Proxy ใน ฺBrowser ของแต่ละเครื่องที่จะใช้อินเตอร์เน็ต ชี้ไปยัง Proxy Server ที่ทำหน้าที่เก็บข้อมูลการใช้งาน</p>
<p>แต่ถ้าเราไม่สามารถควบคุมดูแลได้ หรือเครื่องที่ใช้งานมีการเปลี่ยนแปลงตลอดเวลา เช่นให้บริการอินเตอร์เน็ต สำหรับผู้มาติดต่องาน</p>
<p>ถ้าเป็นแบบนี้ แนะนำให้คอนฟิก Transparent Proxy บน Linux Router เพื่อให้ทำหน้าที่เก็บข้อมูลการใช้เว็บโดยอัตโนมัติ</p>
<p><span id="more-1519"></span></p>
<h4>ระบบทดสอบ</h4>
<ul>
<li>Linux Router ติดตั้ง Squid มีพอร์ต LAN สองพอร์ต eth0, eth1</li>
<li>เครื่องผู้ใช้งานทั้งหมดต่อพอร์ต eth0 ของ Linux Router</li>
<li>พอร์ต eth1 ของ Linux Router ต่อไปยังอินเตอร์เน็ต</li>
</ul>
<h4></h4>
<h4>Redirect Web Traffic ให้เข้าไปใน Proxy Server</h4>
<p>เริ่มแรกต้องบังคับให้การใช้เว็บอินเตอร์เน็ตทั้งหมดต้องผ่าน Linux Router เข้าพอร์ต eth0 แล้วออกอินเตอร์เน็ตทางพอร์ต eth1</p>
<p>ถ้าเราต้องการให้การใช้เว็บ (TCP Port 80) ทั้งหมด เข้าพอร์ต eth0 ต้องผ่านเข้าไปใน Proxy Server (TCP Port 3128) ก่อน เพื่อให้เก็บข้อมูลการใช้งาน สามารถใช้คำสั่ง iptables ตามตัวอย่าง</p>
<pre>
[root@router ~]# <b>iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3128</b>
</pre>
<h4>คอนฟิก Squid ให้ทำหน้าที่เป็น Transparent Proxy</h4>
<p>อย่างที่สองคือต้องแก้ไขไฟล์คอนฟิก Squid ซึ่งอยู่ใน /etc/squid/squid.conf</p>
<p>การแก้ไขคอนฟิกขึ้นอยู่กับเวอร์ชั่นของ Squid ที่ติดตั้ง</p>
<p>คำแนะนำ : เพื่อคุณสมบัติและประสิทธิภาพที่ดีกว่า แนะนำให้ใช้เวอร์ชั่นใหม่ล่าสุดที่สามารถติดตั้งได้</p>
<p><span style="text-decoration: underline;"><strong>เวอร์ชั่นเก่ากว่า 2.6</strong></span></p>
<pre>
httpd_accel_host virtual
httpd_accel_port 80
httpd_accel_with_proxy on
httpd_accel_uses_host_header on
</pre>
<p><span style="text-decoration: underline;"><strong>เวอร์ชั่น 2.6 &#8211; 3.0</strong></span></p>
<pre>
http_port 3128 transparent
</pre>
<p><span style="text-decoration: underline;"><strong>ตั้งแต่เวอร์ชั่น 3.1</strong></span></p>
<pre>
http_port 3128 intercept
</pre>
<p>หรือ</p>
<pre>
http_port 3128 transparent
</pre>
<p>หลังการแก้ไขคอนฟิกไฟล์ของ squid ต้องรีสตาร์ตเซอร์วิส squid</p>
<pre>
[root@router ~]# <b>service squid restart</b>
</pre>
<p>สามารถดูข้อมูลการใช้งานเว็บได้ในไฟล์ /var/log/squid/access.log</p>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li><a href="http://spalinux.com/2008/05/configure_squid_proxy_server">คอนฟิก Squid Proxy Server</a></li>
<li><a href="http://www.squid-cache.org/" target="_blank">squid : Optimising Web Delivery</a></li>
<li><a href="http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:_Ch32_:_Controlling_Web_Access_with_Squid" target="_blank">Quick HOWTO : Ch32 : Controlling Web Access with Squid</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2011/11/how-to-log-web-traffic-via-linux-router-using-squid-transparent-proxy/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ดักจับ Traffic ใน Network ด้วย tcpdump</title>
		<link>http://spalinux.com/2011/06/using_tcpdump_to_capture_traffic_on_network</link>
		<comments>http://spalinux.com/2011/06/using_tcpdump_to_capture_traffic_on_network#comments</comments>
		<pubDate>Fri, 03 Jun 2011 14:44:19 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Console]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Sniffer]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[tcpdump]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=1351</guid>
		<description><![CDATA[tcpdump เป็นโปรแกรมประเภทเดียวกับ Sniffer, Wireshark คือใช้ในการดักจับ (capture) Traffic หรือ Packet ที่ รับ/ส่ง เข้า/ออก ระหว่างพอร์ตแลน (LAN) ของเซิรฟ์เวอร์เครื่องที่รันคำสั่ง และอุปกรณ์เครือข่าย (Router, Switch, HUB) มีประโยชน์อย่างมาก เพื่อใช้ในการวิเคราะห์ ตรวจสอบ หรือแก้ปัญหาเกี่ยวกับ Network ได้ tcpdump ต้องรันด้วย root หรือเทียบเท่า และรันแบบ command line ติดตั้งมาเป็นดีฟอลต์บนลีนุกซ์เกือบทุกตระกูล เวอร์ชั่น จึงใช้งานได้สะดวก ไม่ต้องติดตั้งเพิ่มเติมเหมือนโปรแกรมอื่นๆ ในที่นี้ขอแนะนำวิธีการใช้งานเบื้องต้นของ tcpdump รันคำสั่ง tcpdump ล็อกอินเป็น root แล้วพิมพ์คำสั่ง tcpdump หมายเหตุ พอร์ตที่ใช้ในดักจับ packet ไม่จำเป็นต้องใส่ IP Address หรือเป็น IP ในกลุ่มเดียวกับ IP อื่นๆ [...]]]></description>
			<content:encoded><![CDATA[<p>tcpdump เป็นโปรแกรมประเภทเดียวกับ Sniffer, Wireshark คือใช้ในการดักจับ (capture) Traffic หรือ Packet ที่ รับ/ส่ง เข้า/ออก ระหว่างพอร์ตแลน (LAN) ของเซิรฟ์เวอร์เครื่องที่รันคำสั่ง และอุปกรณ์เครือข่าย (Router, Switch, HUB)</p>
<p>มีประโยชน์อย่างมาก เพื่อใช้ในการวิเคราะห์ ตรวจสอบ หรือแก้ปัญหาเกี่ยวกับ Network ได้</p>
<p>tcpdump ต้องรันด้วย root หรือเทียบเท่า และรันแบบ command line ติดตั้งมาเป็นดีฟอลต์บนลีนุกซ์เกือบทุกตระกูล เวอร์ชั่น จึงใช้งานได้สะดวก ไม่ต้องติดตั้งเพิ่มเติมเหมือนโปรแกรมอื่นๆ</p>
<p>ในที่นี้ขอแนะนำวิธีการใช้งานเบื้องต้นของ tcpdump</p>
<h4><span id="more-1351"></span><br />
รันคำสั่ง tcpdump</h4>
<p>ล็อกอินเป็น root แล้วพิมพ์คำสั่ง tcpdump</p>
<p><strong>หมายเหตุ</strong> พอร์ตที่ใช้ในดักจับ packet ไม่จำเป็นต้องใส่ IP Address หรือเป็น IP ในกลุ่มเดียวกับ IP อื่นๆ ใน Network ที่ต้องการดักจับ ขอให้สถานะ Up พอ</p>
<p>หากไม่ระบุออปชั่นใดๆ เลย tcpdump จะเลือกดักจับ packet ที่เข้าออก พอร์ตแลนแรก โดยทั่วไปคือ eth0</p>
<p>ตัวอย่างการรันคำสั่งแบบไม่ระบุออปชั่น</p>
<pre>[root@server ~]# <strong>tcpdump
</strong>tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
09:15:53.948422 IP 192.168.1.102.jwalkserver &gt; server.example.com.ssh: Flags [.], ack 1108, win 64623, length 0
09:15:53.955117 IP server.example.com.ssh &gt; 192.168.1.102.jwalkserver: Flags [P.], seq 1108:1384, ack 1, win 8576, length 276
09:15:53.963948 IP server.example.com.ssh &gt; 192.168.1.102.jwalkserver: Flags [P.], seq 1384:1548, ack 1, win 8576, length 164
09:15:53.964191 IP 192.168.1.102.jwalkserver &gt; server.example.com.ssh: Flags [.], ack 1548, win 64183, length 0
09:15:53.972707 IP server.example.com.ssh &gt; 192.168.1.102.jwalkserver: Flags [P.], seq 1548:1824, ack 1, win 8576, length 276
<span style="color: #ff0000;"><strong>^C</strong></span></pre>
<pre>102 packets captured
102 packets received by filter
0 packets dropped by kernel</pre>
<p>กด [Ctrl-C] เพื่อออกจากคำสั่ง tcpdump ด้านล่างจะมีรายงานสรุปว่า ดักจับได้กี่ packet</p>
<p>ผลลัพธ์ที่แสดงจากคำสั่ง tcpdump จะแตกต่างกันไปขึ้นกับ Network Protocol ที่รับ/ส่ง เช่นถ้าเป็น IP Protocol (TCP, UDP) รูปแบบจะเป็น</p>
<ul>
<li>เวลา</li>
<li>IP</li>
<li>[Source IP Address].[Source Port]</li>
<li>[Destination Address].[Destination Port]</li>
<li>IP, TCP, UDP Headers</li>
</ul>
<p> </p>
<h4>เลือกพอร์ตที่ดักจับ</h4>
<p>ระบุออปชั่น &#8220;-i&#8221; แล้วตามด้วยชื่อพอร์ต เช่น ต้องการจับ packet ที่เข้าออก eth1</p>
<pre>[root@server ~]# <strong>tcpdump -i eth1
</strong>tcpdump: WARNING: eth1: no IPv4 address assigned
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth1, link-type EN10MB (Ethernet), capture size 65535 bytes
<span style="color: #ff0000;"><strong>^C</strong></span></pre>
<p>ในที่นี้ พอร์ต eth1 ไม่มีการใส่ IP Address จึงขึ้นฟ้อง &#8220;WARNING: eth1: no IPv4 address assigned&#8221; แต่ก็ยังสามารถดักจับ Traffic ได้</p>
<h4>ไม่ต้องแปลง IP เป็นชื่อ hostname</h4>
<p>ผลลัพธ์ที่แสดงออกมา โปรแกรม tcpdump จะพยายามแปลง IP Address ทั้งต้นทาง ปลายทาง ของ packet ที่ดักจับได้ ให้เป็นชื่อ hostname โดยใช้ไฟล์ /etc/hosts หรือ บริการ DNS</p>
<p>ถ้าหาก traffic มีปริมาณมาก แนะนำให้ปิดคุณสมบัติการพยายามแปลง IP เป็น ชื่อ hostname ออกซะ ด้วยการระบุออปชั่น &#8220;-n&#8221; เพื่อลดโหลด DNS</p>
<pre>[root@server ~]# <strong>tcpdump -i eth0 -l -n
</strong>tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
09:31:10.322145 IP 192.168.1.1.ssh &gt; 192.168.1.102.jwalkserver: Flags [P.], seq 1901277915:1901278111, ack 2244887520, win 8576, length 196
09:31:10.322752 IP 192.168.1.102.jwalkserver &gt; 192.168.1.1.ssh: Flags [.], ack 196, win 65535, length 0
09:31:10.330843 IP 192.168.1.1.ssh &gt; 192.168.1.102.jwalkserver: Flags [P.], seq 196:472, ack 1, win 8576, length 276
09:31:10.332785 IP 192.168.1.1.ssh &gt; 192.168.1.102.jwalkserver: Flags [P.], seq 472:636, ack 1, win 8576, length 164
09:31:10.333209 IP 192.168.1.102.jwalkserver &gt; 192.168.1.1.ssh: Flags [.], ack 636, win 65095, length 0
<span style="color: #ff0000;">^C</span></pre>
<p> </p>
<h4>ไม่ต้องแปลง Port Number เป็นชื่อ Port Name</h4>
<p>หากต้องการแสดงชื่อพอร์ต (TCP, UDP ports) เป็นตัวเลข (ไฟล์ /etc/services)  ให้ระบุออปชั่น &#8220;-n&#8221; เพิ่มอีกหนึ่ง หรือระบุเป็น &#8220;-nn&#8221; เลย</p>
<pre>[root@server ~]# <strong>tcpdump -i eth0 -l -nn
</strong>tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
09:39:38.800430 IP 192.168.1.102.1289 &gt; 192.168.1.1.22: Flags [.], ack 196, win 65535, length 0
09:39:38.802793 IP 192.168.1.1.22 &gt; 192.168.1.102.1289: Flags [P.], seq 196:456, ack 1, win 8576, length 260
09:39:38.805709 IP 192.168.1.1.22 &gt; 192.168.1.102.1289: Flags [P.], seq 456:604, ack 1, win 8576, length 148
09:39:38.805963 IP 192.168.1.102.1289 &gt; 192.168.1.1.22: Flags [.], ack 604, win 65127, length 0
09:39:38.808655 IP 192.168.1.1.22 &gt; 192.168.1.102.1289: Flags [P.], seq 604:848, ack 1, win 8576, length 244
<span style="color: #ff0000;"><strong>^C</strong></span></pre>
<h4>ผลลัพธ์แบบสั้นๆ </h4>
<p>หากไม่สนใจ ข้อมูลใน IP, TCP, UDP Headers ต้องการรู้แค่ว่า IP อะไรคุยกัน ใช้พอร์ตอะไร แค่นั้นพอ ให้ระบุออปชั่น &#8220;-q&#8221;</p>
<pre>[root@server ~]# <strong>tcpdump -i eth0 -l -nn -q
</strong>tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
09:40:48.472427 IP 192.168.1.1.22 &gt; 192.168.1.102.1289: tcp 196
09:40:48.473006 IP 192.168.1.102.1289 &gt; 192.168.1.1.22: tcp 0
09:40:48.479252 IP 192.168.1.1.22 &gt; 192.168.1.102.1289: tcp 164
09:40:48.487003 IP 192.168.1.1.22 &gt; 192.168.1.102.1289: tcp 100
09:40:48.487311 IP 192.168.1.102.1289 &gt; 192.168.1.1.22: tcp 0
<span style="color: #ff0000;"><strong>^C</strong></span></pre>
<p> </p>
<h4>แสดงข้อมูล Layer 2 (MAC Address)</h4>
<p>ระบุออปชั่น &#8220;-e&#8221;  หากต้องการแสดงข้อมูล Layer 2 หรือแสดง Source, Destination MAC Address ด้วย</p>
<pre>[root@server ~]# <strong>tcpdump -i eth0 -l -nn -e -q
</strong>tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
09:44:05.644395 00:11:22:33:44:55 &gt; 00:55:66:77:88:99, IPv4, length 250: 192.168.1.1.22 &gt; 192.168.1.102.1289: tcp 196
09:44:05.644959 00:55:66:77:88:99 &gt; 00:11:22:33:44:55, IPv4, length 60: 192.168.1.102.1289 &gt; 192.168.1.1.22: tcp 0
09:44:05.652121 00:11:22:33:44:55 &gt; 00:55:66:77:88:99, IPv4, length 314: 192.168.1.1.22 &gt; 192.168.1.102.1289: tcp 260
09:44:05.660897 00:11:22:33:44:55 &gt; 00:55:66:77:88:99, IPv4, length 218: 192.168.1.1.22 &gt; 192.168.1.102.1289: tcp 164
09:44:05.661173 00:55:66:77:88:99 &gt; 00:11:22:33:44:55, IPv4, length 60: 192.168.1.102.1289 &gt; 192.168.1.1.22: tcp 0
<span style="color: #ff0000;"><strong>^C</strong></span></pre>
<h4> <br />
save ผลลัพธ์เก็บในไฟล์</h4>
<p>หากต้องการบันทึก (save) ผลลัพธ์ที่ดักจับได้ ให้เหมือนกับหน้าจอที่แสดงขึ้นมา ก็ใช้การ redirection</p>
<p>ตัวอย่าง การเก็บผลลัพธ์ลงไฟล์ ให้เหมือนกับที่แสดงขึ้นมา</p>
<pre>[root@server ~]# <strong>tcpdump -i eth0 -l -nn -q &gt; catpure-display.log
</strong>tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
<span style="color: #ff0000;"><strong>^C</strong></span>
7 packets captured
7 packets received by filter
0 packets dropped by kernel</pre>
<pre>หากต้องการหยุด ก็กดปุ่ม [Ctrl-C] เหมือนกัน</pre>
<p>ใช้คำสั่ง cat เพื่อดูเนื้อหาไฟล์ที่บันทึก</p>
<pre>[root@server ~]# <strong>cat capture-display.log
</strong>09:57:08.118314 IP 192.168.1.1.22 &gt; 192.168.1.102.1289: tcp 196
09:57:08.118515 IP 192.168.1.102.1289 &gt; 192.168.1.1.22: tcp 0
09:57:09.138258 IP 192.168.1.102.1289 &gt; 192.168.1.1.22: tcp 36
09:57:09.355761 IP 192.168.1.102.1289 &gt; 192.168.1.1.22: tcp 36
09:57:09.356025 IP 192.168.1.1.22 &gt; 192.168.1.102.1289: tcp 0
<span style="color: #ff0000;"><strong>^C</strong></span></pre>
<p> แต่ถ้าต้องการบันทึกแบบเต็มรูปแบบ ให้ใช้ออปชั่น &#8220;-w&#8221; แล้วตามด้วยชื่อไฟล์ โดยทั่วไปนิยมบันทึกเป็นไฟล์นามสกุล &#8220;.cap&#8221;</p>
<pre>[root@server ~]# <strong>tcpdump -i eth0 -w capture-raw.cap
</strong>tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
<strong><span style="color: #ff0000;">^C</span></strong>
24 packets captured
24 packets received by filter
0 packets dropped by kernel</pre>
<p>ไฟล์ที่บันทึกด้วยออปชั่น &#8220;-w&#8221; สามารถนำมาเปิดย้อนหลังด้วยคำสั่ง tcpdump ตามด้วยออปชั่น &#8220;-r&#8221;  นอกจากนี้ ยังสามารถนำไปเปิดกับโปรแกรม Wireshark ได้อีกด้วย</p>
<pre>[root@server ~]# <strong>tcpdump -r capture-raw.cap -l -nn
</strong>reading from file capture-raw.cap, link-type EN10MB (Ethernet)
10:00:14.959339 IP 192.168.1.102.1289 &gt; 192.168.1.1.22: Flags [P.], seq 105:157, ack 236, win 65431, length 52
10:00:14.972070 IP 192.168.1.1.22 &gt; 192.168.1.102.1289: Flags [P.], seq 236:288, ack 157, win 8576, length 52
10:00:15.137079 IP 192.168.1.102.1289 &gt; 192.168.1.1.22: Flags [.], ack 288, win 65379, length 0
10:00:15.221339 IP 192.168.1.102.1289 &gt; 192.168.1.1.22: Flags [P.], seq 157:209, ack 288, win 65379, length 52
10:00:15.227905 IP 192.168.1.1.22 &gt; 192.168.1.102.1289: Flags [P.], seq 288:340, ack 209, win 8576, length 52
<span style="color: #ff0000;"><strong>^C</strong></span></pre>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li><a href="http://spalinux.com/2008/09/verify_lan_network_interface_status_on_linux">ตรวจสอบสถานะของการ์ดเน็ตเวิร์กบนลีนุกซ์</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2011/06/using_tcpdump_to_capture_traffic_on_network/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>จำกัดจำนวน login พร้อมกันของผู้ใช้เดียวกัน</title>
		<link>http://spalinux.com/2011/05/limit_maximum_number_of_logins_for_user</link>
		<comments>http://spalinux.com/2011/05/limit_maximum_number_of_logins_for_user#comments</comments>
		<pubDate>Sun, 08 May 2011 07:13:52 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Authentication]]></category>
		<category><![CDATA[Linux Shell]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[limit]]></category>
		<category><![CDATA[login]]></category>
		<category><![CDATA[session]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=1325</guid>
		<description><![CDATA[การจำกัด (limit) จำนวนการ login พร้อมกันโดยใช้ชื่อผู้ใช้เดียวกัน สามารถคอนฟิกด้วยออปชั่น &#8220;maxlogins&#8221; ในไฟล์ /etc/security/limits.conf คำอธิบายออปชั่น &#8220;maxlogins&#8221; คือ max number of logins for this user คอนฟิกได้สองแบบคือ จำกัดเป็นรายคน เช่น ชื่อผู้ใช้ user1 สามารถ login ได้สูงสุดพร้อมกันได้แค่ 2 sessions แต่ถ้าต้องการจำกัดผู้ใช้ที่อยู่ในกลุ่ม (group) ให้เติมเครื่องหมาย @ ข้างหน้าชื่อกลุ่ม ตัวอย่างคอนฟิก จำกัดผู้ใช้ user1 ให้ login พร้อมกันได้แค่ 2 sessions เท่านั้น [root@server ~]# cat /etc/security/limits.conf user1           -       maxlogins       2 หลังแก้ไขไฟล์แล้ว คอนฟิกใหม่มีผลต่อการ login ครั้งต่อไปเลย [...]]]></description>
			<content:encoded><![CDATA[<p>การจำกัด (limit) จำนวนการ login พร้อมกันโดยใช้ชื่อผู้ใช้เดียวกัน สามารถคอนฟิกด้วยออปชั่น &#8220;maxlogins&#8221; ในไฟล์ /etc/security/limits.conf</p>
<p>คำอธิบายออปชั่น &#8220;maxlogins&#8221; คือ max number of logins for this user</p>
<p><span id="more-1325"></span></p>
<p>คอนฟิกได้สองแบบคือ จำกัดเป็นรายคน เช่น ชื่อผู้ใช้ user1 สามารถ login ได้สูงสุดพร้อมกันได้แค่ 2 sessions แต่ถ้าต้องการจำกัดผู้ใช้ที่อยู่ในกลุ่ม (group) ให้เติมเครื่องหมาย @ ข้างหน้าชื่อกลุ่ม</p>
<p>ตัวอย่างคอนฟิก จำกัดผู้ใช้ user1 ให้ login พร้อมกันได้แค่ 2 sessions เท่านั้น</p>
<pre>[root@server ~]# <strong>cat /etc/security/limits.conf
</strong>user1           -       maxlogins       2</pre>
<p>หลังแก้ไขไฟล์แล้ว คอนฟิกใหม่มีผลต่อการ login ครั้งต่อไปเลย ไม่จำเป็นต้องรีสตาร์ตโปรแกรม หรือเซอร์วิสใด</p>
<p>ตัวอย่างข้อความในไฟล์ /var/log/secure ที่เกิดขึ้น ระหว่างการทดสอบ login</p>
<p>login ด้วย user1 ครั้งแรก ได้</p>
<pre>Jul  8 13:21:19 server sshd[2375]: Accepted password for user1 from 192.168.1.12 port 4310 ssh2
Jul  8 13:21:19 server sshd[2375]: pam_unix(sshd:session): session opened for user user1 by (uid=0)</pre>
<p>login ด้วย user1 ครั้งที่ 2 ก็ได้</p>
<pre>Jul  8 13:21:39 server sshd[2400]: Accepted password for user1 from 192.168.1.12 port 4311 ssh2
Jul  8 13:21:39 server sshd[2400]: pam_unix(sshd:session): session opened for user user1 by (uid=0)</pre>
<p>ใช้คำสั่ง w เพื่อดูผู้ใช้ที่ login อยู่</p>
<pre>[user1@server ~]$ <strong>w</strong>
 13:21:49 up 14 min,  3 users,  load average: 0.07, 0.19, 0.25
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
admin    pts/0    192.168.1.12         13:19   35.00s  0.72s  0.18s sshd: admin [priv]
user1    pts/1    192.168.1.12         13:21   30.00s  0.20s  0.20s -bash
user1    pts/2    192.168.1.12         13:21    0.00s  0.25s  0.04s w</pre>
<p>login ด้วย user1 ครั้งที่ 3 จะไม่ได้แล้ว</p>
<pre>Jul  8 13:22:00 server sshd[2426]: Accepted password for user1 from 192.168.1.12 port 4312 ssh2
Jul  8 13:22:00 server sshd[2426]: <span style="color: #ff0000;"><strong>pam_limits(sshd:session): Too many logins (max 2) for user1
</strong></span>Jul  8 13:22:00 server sshd[2426]: pam_unix(sshd:session): session opened for user user1 by (uid=0)
Jul  8 13:22:00 server sshd[2426]: error: PAM: pam_open_session(): Permission denied</pre>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2011/05/limit_maximum_number_of_logins_for_user/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ล็อกอินผิดมากเกิน แบนซะด้วย fail2ban</title>
		<link>http://spalinux.com/2011/05/ban_failed_login_attempts_using_fail2ban</link>
		<comments>http://spalinux.com/2011/05/ban_failed_login_attempts_using_fail2ban#comments</comments>
		<pubDate>Sat, 07 May 2011 09:01:08 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Authentication]]></category>
		<category><![CDATA[Firewall]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[SSH]]></category>
		<category><![CDATA[fail2ban]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=1316</guid>
		<description><![CDATA[หากเซิร์ฟเวอร์ของคุณตั้งอยู่บนอินเตอร์เน็ต เพื่อให้บริการเว็บไซต์หรืออื่นๆ และคุณจำเป็นต้องเปิด SSH เพื่อสามารถ login เข้าไปตรวจสอบสถานะของเครื่องได้ คุณต้องเคยเจอปัญหานี้แน่นอน คือมีการพยายามเจาะระบบด้วยการ ssh เข้ามา ด้วย user, password ต่างๆ ที่คาดว่าจะมีในเครื่อง ตัวอย่างไฟล์ /var/log/secure แสดงถึงการพยายาม ssh แต่ไม่สำเร็จ May  2 16:39:27 server sshd[8309]: Invalid user john from x.x.x.x May  2 16:39:27 server sshd[8310]: input_userauth_request: invalid user john May  2 16:39:27 server sshd[8309]: pam_unix(sshd:auth): check pass; user unknown May  2 16:39:27 server sshd[8309]: pam_unix(sshd:auth): [...]]]></description>
			<content:encoded><![CDATA[<p>หากเซิร์ฟเวอร์ของคุณตั้งอยู่บนอินเตอร์เน็ต เพื่อให้บริการเว็บไซต์หรืออื่นๆ และคุณจำเป็นต้องเปิด SSH เพื่อสามารถ login เข้าไปตรวจสอบสถานะของเครื่องได้</p>
<p>คุณต้องเคยเจอปัญหานี้แน่นอน คือมีการพยายามเจาะระบบด้วยการ ssh เข้ามา ด้วย user, password ต่างๆ ที่คาดว่าจะมีในเครื่อง</p>
<p><span id="more-1316"></span></p>
<p>ตัวอย่างไฟล์ /var/log/secure แสดงถึงการพยายาม ssh แต่ไม่สำเร็จ</p>
<pre>May  2 16:39:27 server sshd[8309]: Invalid user john from x.x.x.x
May  2 16:39:27 server sshd[8310]: input_userauth_request: invalid user john
May  2 16:39:27 server sshd[8309]: pam_unix(sshd:auth): check pass; user unknown
May  2 16:39:27 server sshd[8309]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=x.x.x.x
May  2 16:39:27 server sshd[8309]: pam_succeed_if(sshd:auth): error retrieving information about user john
May  2 16:39:29 server sshd[8309]: Failed password for invalid user john from x.x.x.x port 3291 ssh2
May  2 16:39:29 server sshd[8310]: Received disconnect from x.x.x.x: 11: Bye Bye</pre>
<pre> </pre>
<p>การป้องกัน หรือคำแนะนำอย่างแรก ที่พึงกระทำคือ ตั้ง user, password ให้ยากต่อการคาดเดา แต่เท่านั้นอาจไม่เพียงพอ</p>
<p>บทความนี้ขอเสนอวิธีการป้องกันด้วย fail2ban ซึ่งจะช่วยแบน ip ที่พยายาม login แต่ไม่สำเร็จได้</p>
<p>หลักการทำงานคร่าวๆ คือ โปรแกรม fail2ban จะคอยตรวจสอบไฟล์ที่ตั้งไว้ โดยค้นหาคำหรือประโยคที่เกิดขึ้นในไฟล์ เมื่อมีการ failed attempts เกิดขึ้นถึงจำนวนครั้งที่กำหนด fail2ban จะทำการบางอย่างที่ตั้งไว้ เช่น รันคำสั่ง iptables เพื่อ DROP packets ได้</p>
<h4>ติดตั้งไฟล์ rpm</h4>
<p>ในที่นี้ทดสอบบน Fedora 14 ต้องติดตั้งไฟล์ rpm เพิ่มเติมดังนี้</p>
<pre>[root@fc14-x64 ~]# <strong>rpm -ivh gamin-python-0.1.10-8.fc14.x86_64.rpm
</strong>[root@fc14-x64 ~]# <strong>rpm -ivh shorewall-4.4.11.1-1.fc14.noarch.rpm
</strong>[root@fc14-x64 ~]# <strong>rpm -ivh fail2ban-0.8.4-25.fc14.noarch.rpm</strong></pre>
<p>เพื่อความชัดเจนในการทดสอบ จะรันคำสั่ง service iptables stop เพื่อเคลียร์ rule ของ iptables ทั้งหมดออกก่อน</p>
<pre>[root@fc14-x64 ~]# <strong>service iptables stop
</strong>iptables: Flushing firewall rules:                         [  OK  ]
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Unloading modules:                               [  OK  ]</pre>
<p>ใช้คำสั่ง iptables เพื่อแสดง rule ที่ใช้งานอยู่</p>
<pre>[root@fc14-x64 ~]# <strong>iptables -L -v -n
</strong>Chain INPUT (policy ACCEPT 46 packets, 3176 bytes)
 pkts bytes target     prot opt in     out     source               destination</pre>
<pre>Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination</pre>
<pre>Chain OUTPUT (policy ACCEPT 40 packets, 5272 bytes)
 pkts bytes target     prot opt in     out     source               destination</pre>
<p>ใช้คำสั่ง service เพื่อสตาร์ต fail2ban</p>
<pre>[root@fc14-x64 ~]# <strong>service fail2ban start
</strong>Starting fail2ban:                                         [  OK  ]</pre>
<p>ใช้คำสั่ง ps เพื่อดูโปรเซสของ fail2ban</p>
<pre>[root@fc14-x64 ~]# <strong>ps -ef | grep fail2ban
</strong>root      1151     1  0 23:32 ?        00:00:00 /usr/bin/python /usr/bin/fail2ban-server -b -s /var/run/fail2ban/fail2ban.sock -x</pre>
<p>ดูในไฟล์ /var/log/messages แสดงการเริ่มต้นทำงานของ fail2ban</p>
<pre>[root@fc14-x64 ~]# <strong>tail /var/log/messages</strong></pre>
<pre>May  6 23:35:32 fc14-x64 fail2ban.server : INFO   Changed logging target to SYSLOG for Fail2ban v0.8.4
May  6 23:35:32 fc14-x64 fail2ban.jail   : INFO   Creating new jail 'ssh-iptables'
May  6 23:35:32 fc14-x64 fail2ban.jail   : INFO   Jail 'ssh-iptables' uses Gamin
May  6 23:35:32 fc14-x64 fail2ban.filter : INFO   Added logfile = /var/log/secure
May  6 23:35:32 fc14-x64 fail2ban.filter : INFO   Set maxRetry = 5
May  6 23:35:32 fc14-x64 fail2ban.filter : INFO   Set findtime = 600
May  6 23:35:32 fc14-x64 fail2ban.actions: INFO   Set banTime = 600
May  6 23:35:32 fc14-x64 fail2ban.jail   : INFO   Jail 'ssh-iptables' started</pre>
<p>ดีฟอลต์คอนฟิกไฟล์ rpm ที่ได้มาจาก Fedora 14 จะตรวจสอบเฉพาะการพยายาม SSH โดยดูในไฟล์ /var/log/secure</p>
<p>fail2ban จะสร้าง rule และ chain ใหม่ขึ้นมา ใน iptables</p>
<pre>[root@fc14-x64 ~]# <strong>iptables -L -v -n
</strong>Chain INPUT (policy ACCEPT 92 packets, 7885 bytes)
 pkts bytes target     prot opt in     out     source               destination
<span style="color: #0000ff;"><strong>   53  4052 fail2ban-SSH  tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:22</strong></span></pre>
<pre>Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination</pre>
<pre>Chain OUTPUT (policy ACCEPT 84 packets, 8087 bytes)
 pkts bytes target     prot opt in     out     source               destination</pre>
<pre>Chain <strong><span style="color: #0000ff;">fail2ban-SSH</span> </strong>(1 references)
 pkts bytes target     prot opt in     out     source               destination
<span style="color: #0000ff;"><strong>   53  4052 RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0</strong></span></pre>
<p> </p>
<h4>ไฟล์คอนฟิกของ fail2ban</h4>
<p>ไฟล์คอนฟิกของ fail2ban อยู่ใน /etc/fail2ban/</p>
<p>ไฟล์ /etc/fail2ban/jail.conf จะเป็นการกำหนดการทำงานของ fail2ban</p>
<p>คอนฟิกบางส่วนจากไฟล์ jail.conf</p>
<pre>[root@fc14-x64 ~]# <strong>cat /etc/fail2ban/jail.conf</strong>
...
[DEFAULT]
...
# "bantime" is the number of seconds that a host is banned.
<span style="color: #0000ff;">bantime  = 600</span></pre>
<pre># A host is banned if it has generated "maxretry" during the last "findtime"
# seconds.
<span style="color: #0000ff;">findtime  = 600
</span>...
[ssh-iptables]</pre>
<pre>enabled  = true
filter   = sshd
action   = iptables[name=SSH, port=ssh, protocol=tcp]
           sendmail-whois[name=SSH, dest=root, sender=fail2ban@mail.com]
logpath  = /var/log/secure
maxretry = 5</pre>
<p>คำอธิบายคร่าวๆ จากไฟล์ jail.conf คือ ให้ตรวจสอบ (filter) การ ssh โดยดูในไฟล์ (logpath) /var/log/secure ว่า ถ้ามีการ failed login เกิน (maxretry) ครั้ง ภายในเวลา (findtime) 600 วินาที ให้ทำการ (action) รัน iptables ด้วยออปชั่นในวงเล็บ</p>
<p>สามารถดูรายละเอียด filter ในไฟล์ /etc/fail2ban/filter.d/sshd.conf</p>
<pre>[root@fc14-x64 ~]# <strong>cat /etc/fail2ban/filter.d/sshd.conf
</strong>...
[Definition]</pre>
<pre>_daemon = sshd
...
failregex = ^%(__prefix_line)s(?:error: PAM: )?Authentication failure for .* from &lt;HOST&gt;\s*$
            ^%(__prefix_line)s(?:error: PAM: )?User not known to the underlying authentication module for .* from &lt;HOST&gt;\s*$
            ^%(__prefix_line)sFailed (?:password|publickey) for .* from &lt;HOST&gt;(?: port \d*)?(?: ssh\d*)?$
            ^%(__prefix_line)sROOT LOGIN REFUSED.* FROM &lt;HOST&gt;\s*$
            ^%(__prefix_line)s[iI](?:llegal|nvalid) user .* from &lt;HOST&gt;\s*$
            ^%(__prefix_line)sUser \S+ from &lt;HOST&gt; not allowed because not listed in AllowUsers$
            ^%(__prefix_line)sauthentication failure; logname=\S* uid=\S* euid=\S* tty=\S* ruser=\S* rhost=&lt;HOST&gt;(?:\s+user=.*)?\s*$
            ^%(__prefix_line)srefused connect from \S+ \(&lt;HOST&gt;\)\s*$
            ^%(__prefix_line)sAddress &lt;HOST&gt; .* POSSIBLE BREAK-IN ATTEMPT!*\s*$
            ^%(__prefix_line)sUser \S+ from &lt;HOST&gt; not allowed because none of user's groups are listed in AllowGroups$</pre>
<p>คำอธิบายจากไฟล์คอนฟิก filter คือ ให้ตรวจสอบหาคำหรือประโยคที่ระบุไว้ใน failregex (regular expression)</p>
<p>ส่วน action ที่ทำ หลังจาก maxretry ดูได้ในไฟล์  /etc/fail2ban/action.d/iptables.conf</p>
<pre>[root@fc14-x64 ~]# <strong>cat /etc/fail2ban/action.d/iptables.conf
</strong>...
actionban = iptables -I fail2ban-&lt;name&gt; 1 -s &lt;ip&gt; -j DROP
...
actionunban = iptables -D fail2ban-&lt;name&gt; -s &lt;ip&gt; -j DROP</pre>
<p>คำอธิบาย คือการรันคำสั่ง iptables เพื่อสร้าง rule เพื่อจะ ban &lt;ip&gt; ที่พยายามเข้ามา</p>
<p>และเมื่อเกินเวลา (bantime) 600 วินาที แล้ว ก็รันคำสั่ง iptables เพื่อลบ rule ที่สร้างขึ้น อนุญาตให้ &lt;ip&gt; สามารถเข้ามาได้อีกครั้ง</p>
<h4>ทดสอบการ login fail</h4>
<p><span style="color: #ff0000;"><strong>คำเตือน </strong>การทดลองใช้ fail2ban ให้ลองบนเครื่องที่สามารถ console ได้  เพราะการคอนฟิกหรือลอง login fail จะทำให้คุณไม่สามารถ ssh เข้าเครื่องนั้นได้ ช่วงเวลาหนึ่ง</span></p>
<p>สมมุติให้ลอง ssh login fail ด้วย root จาก 192.168.1.12</p>
<p>ดูไฟล์ /var/log/secure ที่เกิดขึ้นบน server</p>
<pre>[root@fc14-x64 ~]#<strong> tail -f /var/log/secure
</strong>May  6 23:43:47 fc14-x64 unix_chkpwd[1340]: password check failed for user (root)
May  6 23:43:47 fc14-x64 sshd[1338]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.168.1.12  user=root
May  6 23:43:49 fc14-x64 sshd[1338]: Failed password for root from 192.168.1.12 port 34811 ssh2</pre>
<pre>May  6 23:43:56 fc14-x64 unix_chkpwd[1342]: password check failed for user (root)
May  6 23:43:58 fc14-x64 sshd[1338]: Failed password for root from 192.168.1.12 port 34811 ssh2</pre>
<pre>May  6 23:44:00 fc14-x64 unix_chkpwd[1343]: password check failed for user (root)
May  6 23:44:01 fc14-x64 sshd[1338]: Failed password for root from 192.168.1.12 port 34811 ssh2
May  6 23:44:01 fc14-x64 sshd[1339]: Connection closed by 192.168.1.12
May  6 23:44:01 fc14-x64 sshd[1338]: PAM 2 more authentication failures; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.168.1.12  user=root</pre>
<pre>May  6 23:44:16 fc14-x64 unix_chkpwd[1348]: password check failed for user (root)
May  6 23:44:16 fc14-x64 sshd[1346]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.168.1.12  user=root
May  6 23:44:19 fc14-x64 sshd[1346]: Failed password for root from 192.168.1.12 port 34812 ssh2</pre>
<pre>May  6 23:44:22 fc14-x64 unix_chkpwd[1349]: password check failed for user (root)
May  6 23:44:25 fc14-x64 sshd[1346]: Failed password for root from 192.168.1.12 port 34812 ssh2
May  6 23:44:25 fc14-x64 sshd[1347]: Connection closed by 192.168.1.12
May  6 23:44:25 fc14-x64 sshd[1346]: PAM 1 more authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.168.1.12  user=root</pre>
<p>เมื่อ login fail เกินค่า maxretry ที่ตั้งไว้ ในที่นี้คือ 5 ครั้ง สังเกตในไฟล์ /var/log/messages  โปรแกรม fail2ban จะทำการ action ขึ้นมา เพื่อ ban 192.168.1.12</p>
<pre>[root@fc14-x64 ~]# <strong>tail /var/log/messages
</strong>May  6 23:44:27 fc14-x64 &lt;28&gt;<span style="color: #0000ff;">fail2ban.actions: WARNING [ssh-iptables] Ban 192.168.1.12</span></pre>
<p>ใช้คำสั่ง iptables เพื่อตรวจสอบ rule ที่เพิ่มขึ้น</p>
<pre>[root@fc14-x64 ~]# <strong>iptables -L -v -n
</strong>Chain INPUT (policy ACCEPT 61 packets, 10699 bytes)
 pkts bytes target     prot opt in     out     source               destination
  453 37587 fail2ban-SSH  tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           <span style="color: #0000ff;"><strong>tcp dpt:22</strong></span></pre>
<pre>Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination</pre>
<pre>Chain OUTPUT (policy ACCEPT 60 packets, 7044 bytes)
 pkts bytes target     prot opt in     out     source               destination</pre>
<pre>Chain fail2ban-SSH (1 references)
 pkts bytes target     prot opt in     out     source               destination
<span style="color: #0000ff;"><strong>    2   120 DROP       all  --  *      *       192.168.1.12            0.0.0.0/0
</strong></span>  451 37467 RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0</pre>
<p>สังเกตว่า rule ที่สร้างขึ้น จะ DROP เฉพาะการ ssh (tcp 22) เท่านั้น แปลว่า ip ที่ถูก ban ไป จะไม่สามารถ ssh เข้าเครื่อง server ได้อีก แต่ยังสามารถเปิด web (tcp 80) หรืออื่นๆ ได้ตามปกติ</p>
<p>คอนฟิกในไฟล์ jail.conf เมื่อมีการ ban เกิดขึ้น จะมีการส่ง mail หา root ด้วย</p>
<p>ตัวอย่าง mail ที่ส่งให้ root</p>
<pre>From fail2ban@mail.com  Fri May  6 23:44:28 2011
Return-Path: &lt;fail2ban@mail.com&gt;
Date: Fri, 6 May 2011 23:44:27 +0700
Subject: [Fail2Ban] SSH: banned 192.168.1.12
From: Fail2Ban &lt;fail2ban@mail.com&gt;
To: <a href="mailto:root@fc14-x64.example.com">root@fc14-x64.example.com</a>
Status: R</pre>
<pre>Hi,</pre>
<pre>The IP 192.168.1.12 has just been banned by Fail2Ban after 5 attempts against SSH.
...</pre>
<p>เมื่อเวลาผ่านไป เกินเวลา bantime ในที่นี้ 600 วินาที  โปรแกรม fail2ban ก็จะปลดการ ban ออก ดูได้จากไฟล์ /var/log/messsages</p>
<pre>[root@fc14-x64 ~]# <strong>tail /var/log/messages
</strong>May  6 23:44:27 fc14-x64 &lt;28&gt;fail2ban.actions: WARNING [ssh-iptables] Ban 192.168.1.12
May  6 23:54:28 fc14-x64 &lt;28&gt;<span style="color: #0000ff;">fail2ban.actions: WARNING [ssh-iptables] Unban 192.168.1.12</span></pre>
<p>ใช้คำสั่ง iptables เพื่อตรวจสอบ rule ที่ใช้งานอยู่ หลังจาก unban</p>
<pre>[root@fc14-x64 log]# <strong>iptables -L -v -n
</strong>Chain INPUT (policy ACCEPT 561 packets, 50572 bytes)
 pkts bytes target     prot opt in     out     source               destination
 1753  141K fail2ban-SSH  tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:22</pre>
<pre>Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination</pre>
<pre>Chain OUTPUT (policy ACCEPT 501 packets, 50410 bytes)
 pkts bytes target     prot opt in     out     source               destination</pre>
<pre>Chain fail2ban-SSH (1 references)
 pkts bytes target     prot opt in     out     source               destination
 1751  141K RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0</pre>
<p> </p>
<p>ลองนำไปใช้ดูครับ เพิ่มความปลอดภัยให้เครื่องได้อีกระดับ</p>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li><a href="http://www.fail2ban.org/" target="_blank">Fail2ban</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2011/05/ban_failed_login_attempts_using_fail2ban/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ปัญหาการใช้ SSH Public Key Authentication บน Solaris</title>
		<link>http://spalinux.com/2010/06/ssh_public_key_authentication_problem_on_solaris</link>
		<comments>http://spalinux.com/2010/06/ssh_public_key_authentication_problem_on_solaris#comments</comments>
		<pubDate>Sat, 05 Jun 2010 10:40:51 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Authentication]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Solaris]]></category>
		<category><![CDATA[SSH]]></category>
		<category><![CDATA[Troubleshooting]]></category>
		<category><![CDATA[secure shell]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=1110</guid>
		<description><![CDATA[พยายามคอนฟิก Public Key Authentication เพื่อ login เข้าสู่เครื่องที่ติดตั้ง Solaris อยู่นาน ก็ไม่สามารถทำได้ แต่ในที่สุดก็สามารถหาปัญหาได้ เลยมาแชร์ประสบการณ์เผื่อจะเป็นประโยชน์ ทดสอบปัญหา เริ่มต้นเพิ่ม user บนเครื่องที่ติดตั้ง Solaris 10 สมมติว่าชื่อ user1 [root@solaris ~]# useradd user1 [root@solaris ~]# id user1 uid=502(user1) gid=1(other) groups=1(other) แก้ไข home ของ user1 ให้อยู่ใน /export/home/ และสร้างไดเร็คทอรี [root@solaris ~]# cat /etc/passwd ... user1:x:502:1::/export/home/user1:/bin/sh [root@solaris ~]# cd /export/home [root@solaris home]# mkdir user1 [root@solaris home]# chown [...]]]></description>
			<content:encoded><![CDATA[<p>พยายามคอนฟิก Public Key Authentication เพื่อ login เข้าสู่เครื่องที่ติดตั้ง Solaris อยู่นาน ก็ไม่สามารถทำได้ แต่ในที่สุดก็สามารถหาปัญหาได้ เลยมาแชร์ประสบการณ์เผื่อจะเป็นประโยชน์</p>
<p><span id="more-1110"></span></p>
<h4>ทดสอบปัญหา</h4>
<p>เริ่มต้นเพิ่ม user บนเครื่องที่ติดตั้ง Solaris 10 สมมติว่าชื่อ user1</p>
<pre>[root@solaris ~]# <strong>useradd user1
</strong>[root@solaris ~]# <strong>id user1
</strong>uid=502(user1) gid=1(other) groups=1(other)</pre>
<p>แก้ไข home ของ user1 ให้อยู่ใน /export/home/ และสร้างไดเร็คทอรี</p>
<pre>[root@solaris ~]# <strong>cat /etc/passwd
</strong>...
user1:x:502:1::<span style="color: #0000ff;">/export/home/user1</span>:/bin/sh</pre>
<pre>[root@solaris ~]# <strong>cd /export/home
</strong>[root@solaris home]# <strong>mkdir user1
</strong>[root@solaris home]# <strong>chown user1 user1/
</strong>[root@solaris home]# <strong>su - user1
</strong>[user1@solaris ~]$ <strong>pwd
</strong>/export/home/user1</pre>
<p>ต้องการให้ admin1 จากเครื่องที่ติดตั้ง linux สามารถ ssh ด้วย public key authentication เป็น user1 บนเครื่อง Solaris ได้</p>
<p>สร้าง public, private key ของ admin1</p>
<pre>[admin1@linux ~]$ <strong>ssh-keygen -t rsa
</strong>Generating public/private rsa key pair.
Enter file in which to save the key (/home/admin1/.ssh/id_rsa):
Created directory '/home/admin1/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/admin1/.ssh/id_rsa.
Your public key has been saved in /home/admin1/.ssh/id_rsa.pub.</pre>
<pre>[admin1@linux ~]$ <strong>cat .ssh/id_rsa.pub
</strong><span style="color: #0000ff;">ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAtMbbgeFnn6vEo3IAVh... admin1@linux</span></pre>
<p>copy ไฟล์ id_rsa.pub ของ admin1 ไปใส่ไว้ในไฟล์ authorized_keys ของ user1 บนเครื่อง Solaris</p>
<pre>[user1@solaris ~]$ <strong>cat .ssh/authorized_keys
</strong><span style="color: #0000ff;">ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAtMbbgeFnn6vEo3IAVh... admin1@linux</span></pre>
<p>ทดสอบ ssh จากเครื่อง linux</p>
<pre>[admin1@linux ~]$ <strong>ssh -l user1 solaris
</strong>The authenticity of host 'solaris (192.168.1.2)' can't be established.
RSA key fingerprint is ...
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'solaris' (RSA) to the list of known hosts.
Password:</pre>
<p>ขึ้นให้ใส่ password ไม่สามารถ login ด้วย public key authentication ได้</p>
<h4>วิธีการแก้ไขปัญหา</h4>
<p>หลังจากพยายามอยู่นาน ก็พบว่า ssh จะตรวจสอบสถานะ password ของผู้ใช้ด้วย ซึ่งถ้าดูในไฟล์ /etc/shadow จะเห็นว่า user1 จะถูก lock อยู่</p>
<pre>[root@solaris ~]# <strong>cat /etc/shadow
</strong>...
user1:<span style="color: #ff0000;"><strong>*LK*</strong></span>:::::::</pre>
<p>ฟิลด์ที่สองในไฟล์ /etc/shadow คือ encrypted password คำอธิบายจาก man ของ shadow คือ</p>
<pre># <strong>man shadow
</strong>...
     password        An encrypted password for the user generated
                     by crypt(3C), a lock string to indicate that
                     the login is not accessible, or  no  string,
                     which  shows  that  there is no password for
                     the login.</pre>
<pre>                     The lock string is defined as <span style="color: #ff0000;"> *LK*</span>  in  the
                     first four characters of the password field.
...</pre>
<p>การแก้ไขคือ ลบตัวอักษร LK ออก เช่นให้เหลือแต่เครื่องหมาย *</p>
<pre>[root@solaris ~]# <strong>cat /etc/shadow
</strong>...
user1:<span style="color: #ff0000;">*</span>:::::::</pre>
<p>ทดสอบ ssh จากเครื่อง linux อีกครั้ง ก็จะได้ตามที่ต้องการ</p>
<pre>[admin1@linux ~]$ <strong>ssh -l user1 solaris
</strong>[user1@solaris ~]$</pre>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li><a href="http://spalinux.com/2008/10/ssh_secure_shell_login_using_public_key_authentication">SSH – Secure Shell ล็อกอินด้วย Public Key Authentication</a></li>
<li><a href="http://forums.sun.com/thread.jspa?threadID=5229706" target="_blank">Sun Networking Services and Protocols &#8211; SSH PermitEmptyPasswords with PASSREQ</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2010/06/ssh_public_key_authentication_problem_on_solaris/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>คอนฟิก Solaris IP Filter</title>
		<link>http://spalinux.com/2010/05/configure_solaris_ip_filter</link>
		<comments>http://spalinux.com/2010/05/configure_solaris_ip_filter#comments</comments>
		<pubDate>Sat, 22 May 2010 08:46:27 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Firewall]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Solaris]]></category>
		<category><![CDATA[ip filter]]></category>
		<category><![CDATA[solaris 10]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=1104</guid>
		<description><![CDATA[บทความนี้กล่าวถึงวิธีการใช้คำสั่ง ipf เพื่อสร้าง rule ของ Solaris IP Filter แบบง่ายๆ เพื่อใช้กำหนด packet เข้าออกเครื่อง Solaris IP Filter เป็นโปรแกรม Firewall ที่ควบคุม packet เข้า/ออก เครื่องที่ติดตั้ง Solaris ได้ ipf เป็นคำสั่งที่ใช้ในการแก้ไขกฎ (rule) ของ Solaris IP Filter หมายเหตุ ตัวอย่างในบทความนี้ทดสอบบนเครื่องที่ติดตั้ง Solaris 10 10/09 s10x_u8wos_08a X86 ทดสอบกับเครื่องที่สามารถคอนโซลหน้าจอได้เท่านั้น เพราะถ้าคอนฟิก rule ของ Firewall ผิดพลาด อาจทำให้คุณไม่สามารถ remote เช่น Secure Shell ได้ 1. เปิด (Start) เซอร์วิส ipfilter โดยดีฟอลต์จากการติดตั้ง [...]]]></description>
			<content:encoded><![CDATA[<p>บทความนี้กล่าวถึงวิธีการใช้คำสั่ง ipf เพื่อสร้าง rule ของ Solaris IP Filter แบบง่ายๆ เพื่อใช้กำหนด packet เข้าออกเครื่อง</p>
<p><span id="more-1104"></span></p>
<p>Solaris IP Filter เป็นโปรแกรม Firewall ที่ควบคุม packet เข้า/ออก เครื่องที่ติดตั้ง Solaris ได้</p>
<p>ipf เป็นคำสั่งที่ใช้ในการแก้ไขกฎ (rule) ของ Solaris IP Filter</p>
<p>หมายเหตุ</p>
<ul>
<li>ตัวอย่างในบทความนี้ทดสอบบนเครื่องที่ติดตั้ง Solaris 10 10/09 s10x_u8wos_08a X86</li>
<li>ทดสอบกับเครื่องที่สามารถคอนโซลหน้าจอได้เท่านั้น เพราะถ้าคอนฟิก rule ของ Firewall ผิดพลาด อาจทำให้คุณไม่สามารถ remote เช่น Secure Shell ได้</li>
</ul>
<h4>1. เปิด (Start) เซอร์วิส ipfilter</h4>
<p>โดยดีฟอลต์จากการติดตั้ง เซอร์วิส IP Filter จะถูกปิดการใช้งาน</p>
<p>ใช้คำสั่ง svcs ตรวจสอบสถานะ</p>
<pre># <strong>svcs -av | grep ipfilter
</strong>disabled       -             15:25:36      - svc:/network/ipfilter:default</pre>
<p>ใช้คำสั่ง svcadm เพื่อเปิดการเซอร์วิส</p>
<pre># <strong>svcadm enable ipfilter</strong></pre>
<pre># <strong>svcs -av | grep ipfilter
</strong>online         -             15:27:14      - svc:/network/ipfilter:default</pre>
<h4>2. เปิดคุณสมบัติ (Enable) IP Filter</h4>
<p>ขั้นต่อมา ใช้คำสั่ง ipf -E เพื่อเปิดคุณสมบัติ IP Filter</p>
<pre># <strong>ipf -E</strong></pre>
<h4>3. ทดลองการสร้าง rule แบบง่ายๆ</h4>
<p>สร้างไฟล์ /etc/ipf/ipf.conf เพื่อกำหนด rule ที่ต้องการ</p>
<p>ตัวอย่างเช่น ต้องการสร้าง rule เพื่อกำหนดให้เฉพาะเครื่องที่มี IP 192.168.1.2 เท่านั้นที่สามารถ ping (ICMP) เข้ามาที่เครื่องทางพอร์ต e1000g0 ได้</p>
<pre># <strong>cat /etc/ipf/ipf.conf</strong></pre>
<pre>block in on e1000g0 proto icmp from any to any
pass in on e1000g0 proto icmp from 192.168.1.2/32 to any</pre>
<p>หลังจากสร้างไฟล์เรียบร้อย พิมพ์คำสั่ง ipf -f ตามด้วยไฟล์ ipf.conf เพื่อเริ่มการบังคับใช้ rule ที่สร้างขึ้น</p>
<pre># <strong>ipf -f /etc/ipf/ipf.conf</strong></pre>
<p>*** 4. ลบ (Flush) rule ออกไป ***</p>
<p>หากต้องการยกเลิก rule ที่สร้างขึ้น ใช้คำสั่ง ipf -F เพื่อ ลบ (flush) rule ที่มีออกไป</p>
<pre># <strong>ipf -F a</strong></pre>
<h4>5. ปิดคุณสมบัติ (Disable) IP Filter</h4>
<p>ใช้คำสั่ง ipf -D เพื่อปิดคุณสมบัติ IP Filter</p>
<pre># <strong>ipf -D</strong></pre>
<h4>ตัวอย่าง rule</h4>
<p>มีตัวอย่างการสร้างไฟล์ ipf.conf เพื่อกำหนด rule แบบต่างๆ /usr/share/ipfilter/examples/</p>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li>man ipf</li>
<li><a href="http://docs.sun.com/app/docs/doc/816-4554/eupsq?l=en&amp;a=view" target="_blank">System Administration Guide: Solaris IP Filter (Overview)</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2010/05/configure_solaris_ip_filter/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ติดตั้งและทดสอบ FreeRADIUS เบื้องต้น</title>
		<link>http://spalinux.com/2009/11/basic_install_freeradius</link>
		<comments>http://spalinux.com/2009/11/basic_install_freeradius#comments</comments>
		<pubDate>Sat, 28 Nov 2009 07:44:09 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Authentication]]></category>
		<category><![CDATA[RADIUS]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=974</guid>
		<description><![CDATA[FreeRADIUS เป็นโปรแกรมที่ทำหน้าที่ RADIUS แบบฟรี ที่คนใช้งานกันมากที่สุด โดยมีคุณสมบัติเทียบเท่ากับ commercial RADIUS หลายๆ ตัว บทความนี้จะกล่าวถึงวิธีการติดตั้ง และทดสอบ FreeRADIUS ในเบื้องต้น เพื่อจะสามารถต่อยอด และคอนฟิกอื่นๆ เพิ่มเติมได้ ติดตั้งไฟล์ rpm ในที่นี้จะทดสอบบน Fedora 11 (x86_64) โดยใช้ไฟล์ rpm ในส่วน updates เพื่อติดตั้งและใช้งาน ใช้คำสั่ง rpm เพื่อติดตั้งไฟล์ ต่างๆ ดังนี้ [root@fc11-64a ~]# rpm -i freeradius-libs-2.1.7-1.fc11.x86_64.rpm [root@fc11-64a ~]# rpm -i freeradius-2.1.7-1.fc11.x86_64.rpm [root@fc11-64a ~]# rpm -i freeradius-utils-2.1.7-1.fc11.x86_64.rpm หมายเหตุ การติดตั้ง freeradius-utils จำเป็นต้องมี perl(DBI) ติดตั้งอยู่ก่อนแล้ว ตัวอย่าง [...]]]></description>
			<content:encoded><![CDATA[<p>FreeRADIUS เป็นโปรแกรมที่ทำหน้าที่ RADIUS แบบฟรี ที่คนใช้งานกันมากที่สุด โดยมีคุณสมบัติเทียบเท่ากับ commercial RADIUS หลายๆ ตัว</p>
<p>บทความนี้จะกล่าวถึงวิธีการติดตั้ง และทดสอบ FreeRADIUS ในเบื้องต้น เพื่อจะสามารถต่อยอด และคอนฟิกอื่นๆ เพิ่มเติมได้</p>
<h4><span id="more-974"></span><br />
ติดตั้งไฟล์ rpm</h4>
<p>ในที่นี้จะทดสอบบน Fedora 11 (x86_64) โดยใช้ไฟล์ rpm ในส่วน updates เพื่อติดตั้งและใช้งาน</p>
<p>ใช้คำสั่ง rpm เพื่อติดตั้งไฟล์ ต่างๆ ดังนี้</p>
<pre>[root@fc11-64a ~]# <strong>rpm -i freeradius-libs-2.1.7-1.fc11.x86_64.rpm
</strong>[root@fc11-64a ~]# <strong>rpm -i freeradius-2.1.7-1.fc11.x86_64.rpm
</strong>[root@fc11-64a ~]# <strong>rpm -i freeradius-utils-2.1.7-1.fc11.x86_64.rpm</strong></pre>
<p>หมายเหตุ การติดตั้ง freeradius-utils จำเป็นต้องมี perl(DBI) ติดตั้งอยู่ก่อนแล้ว</p>
<p>ตัวอย่าง error หากไม่มี perl(DBI) ติดตั้งอยู่</p>
<pre>[root@fc11-64a ~]# <strong>rpm -i freeradius-utils-2.1.7-1.fc11.x86_64.rpm
</strong>error: Failed dependencies:
        perl(DBI) is needed by freeradius-utils-2.1.7-1.fc11.x86_64</pre>
<p>วิธีการแก้ไขปัญหา</p>
<pre>[root@fc11-64a ~]# <strong>rpm -i perl-DBI-1.607-2.fc11.x86_64.rpm</strong></pre>
<h4>รันเซอร์วิส radiusd</h4>
<p>หลังจากการติดตั้ง ใช้คำสั่ง service เพื่อรันเซอร์วิส radiusd</p>
<pre>[root@fc11-64a ~]# <strong>service radiusd start
</strong>Starting RADIUS server:                                    [<strong><span style="color: #ff0000;">FAILED</span></strong>]</pre>
<p>หากยังไม่แก้ไขไฟล์คอนฟิกเลย จะไม่สามารถรันเซอร์วิส radiusd ได้ ขึ้น [FAILED]</p>
<p>เมื่อเกิดปัญหาในการใช้งาน radiusd ไฟล์หนึ่งที่สามารถตรวจสอบปัญหาได้คือไฟล์ /var/log/radius/radius.log</p>
<pre>[root@fc11-64a ~]# <strong>tail /var/log/radius/radius.log
</strong>Sat Nov 28 12:15:09 2009 : Error: rlm_eap: SSL error error:02001002:system library:fopen:<span style="color: #ff0000;">No such file or directory
</span>Sat Nov 28 12:15:09 2009 : Error: rlm_eap_tls: <span style="color: #ff0000;">Error reading certificate file /etc/raddb/certs/server.pem
</span>Sat Nov 28 12:15:09 2009 : Error: rlm_eap: Failed to initialize type tls
Sat Nov 28 12:15:09 2009 : Error: /etc/raddb/eap.conf[17]: Instantiation failed for module "eap"
Sat Nov 28 12:15:09 2009 : Error: /etc/raddb/sites-enabled/inner-tunnel[223]: Failed to find module "eap".
Sat Nov 28 12:15:09 2009 : Error: /etc/raddb/sites-enabled/inner-tunnel[176]: Errors parsing authenticate section.
Sat Nov 28 12:15:09 2009 : Error: Failed to load virtual server inner-tunnel</pre>
<p>ปัญหานี้คือไม่มีไฟล์ /etc/raddb/certs/server.pem ซึ่งเป็น certificate สำหรับการทำ EAP</p>
<p>วิธีการแก้ไขคือสร้างไฟล์ server.pem โดยเข้าไปในไดเร็คทอรี /etc/raddb/certs/ แล้วรันคำสั่ง bootstrap ซึ่งจะสร้างไฟล์ certificate ขึ้นมา</p>
<p>หมายเหตุ เพื่อความง่าย ในที่นี้จะสร้าง certificate ไฟล์ เพื่อทดสอบการใช้งาน radiusd เท่านั้น ในการใช้งานจริงก่อนที่จะสร้าง ควรจะแก้ไขคอนฟิก เพื่อระบุ Certificate Details เพื่อแสดงชื่อหน่วยงานให้ถูกต้อง</p>
<pre>[root@fc11-64a ~]# c<strong>d /etc/raddb/certs/
</strong>[root@fc11-64a certs]# <strong>./bootstrap
</strong>openssl dhparam -out dh 1024
Generating DH parameters, 1024 bit long safe prime, generator 2
This is going to take a long time
.................+......................................................................................................+...+.........+.....+.......................+...................................................................................................+......................................+........................................................................................................+.................................................................+....................+...................................................................................+...................+.......................................+............................................................................+..........................................+.............+....................................+..............................................+...+.....................+...+.....+...............+.............................+..................+...................................................+.....+.................+............................................+.......+................................................................................................+....+.....+............................................................................................................................................................................................................................................+......................+........................................................................................................................................................................................................................................+............+............................+..................+.............................................................................................................................+.....................................................++*++*++*
openssl req -new  -out server.csr -keyout server.key -config ./server.cnf
Generating a 2048 bit RSA private key
.......................+++
.....+++
writing new private key to 'server.key'
-----
openssl req -new -x509 -keyout ca.key -out ca.pem \
                -days `grep default_days ca.cnf | sed 's/.*=//;s/^ *//'` -config ./ca.cnf
Generating a 2048 bit RSA private key
....................................+++
........+++
writing new private key to 'ca.key'
-----
openssl ca -batch -keyfile ca.key -cert ca.pem -in server.csr  -key `grep output_password ca.cnf | sed 's/.*=//;s/^ *//'` -out server.crt -extensions xpserver_ext -extfile xpextensions -config ./server.cnf
Using configuration from ./server.cnf
Check that the request matches the signature
Signature ok
Certificate Details:
        Serial Number: 1 (0x1)
        Validity
            Not Before: Nov 28 05:20:32 2009 GMT
            Not After : Nov 28 05:20:32 2010 GMT
        Subject:
            countryName               = FR
            stateOrProvinceName       = Radius
            organizationName          = Example Inc.
            commonName                = Example Server Certificate
            emailAddress              = admin@example.com
        X509v3 extensions:
            X509v3 Extended Key Usage:
                TLS Web Server Authentication
Certificate is to be certified until Nov 28 05:20:32 2010 GMT (365 days)</pre>
<pre>Write out database with 1 new entries
Data Base Updated
openssl pkcs12 -export -in server.crt -inkey server.key -out server.p12  -passin pass:`grep output_password server.cnf | sed 's/.*=//;s/^ *//'` -passout pass:`grep output_password server.cnf | sed 's/.*=//;s/^ *//'`
openssl pkcs12 -in server.p12 -out <span style="color: #3366ff;">server.pem </span>-passin pass:`grep output_password server.cnf | sed 's/.*=//;s/^ *//'` -passout pass:`grep output_password server.cnf | sed 's/.*=//;s/^ *//'`
MAC verified OK
openssl x509 -inform PEM -outform DER -in ca.pem -out ca.der</pre>
<p>หลังจากสร้างแล้ว ใช้คำสั่ง service เพื่อรันเซอร์วิส radiusd อีกครั้ง</p>
<pre>[root@fc11-64a certs]# <strong>service radiusd start
</strong>Starting RADIUS server:                                    [<span style="color: #ff0000;">FAILED</span>]</pre>
<p>รันครั้งนี้ ก็ยัง [FAILED] อยู่ ถ้าตรวจสอบดูไฟล์ radius.log มีข้อความ &#8220;Permission denied&#8221; ขึ้น ซึ่งหมายถึง radiusd ไม่สามารถอ่านไฟล์ server.pem ได้</p>
<pre>[root@fc11-64a ~]# <strong>tail /var/log/radius/radius.log
</strong>...
Sat Nov 28 12:21:38 2009 : Error: rlm_eap: SSL error error:0200100D:system library:fopen:<span style="color: #ff0000;">Permission denied
</span>Sat Nov 28 12:21:38 2009 : Error: rlm_eap_tls: <span style="color: #ff0000;">Error reading certificate file /etc/raddb/certs/server.pem
</span>Sat Nov 28 12:21:38 2009 : Error: rlm_eap: Failed to initialize type tls
Sat Nov 28 12:21:38 2009 : Error: /etc/raddb/eap.conf[17]: Instantiation failed for module "eap"
Sat Nov 28 12:21:38 2009 : Error: /etc/raddb/sites-enabled/inner-tunnel[223]: Failed to find module "eap".
Sat Nov 28 12:21:38 2009 : Error: /etc/raddb/sites-enabled/inner-tunnel[176]: Errors parsing authenticate section.
Sat Nov 28 12:21:38 2009 : Error: Failed to load virtual server inner-tunnel</pre>
<p>ปัญหานี้เกิดจากเราใช้ root เพื่อรันคำสั่ง bootstrap แล้วไฟล์ที่ถูกสร้างขึ้น owner, group จะเป็น root ทั้งหมด แต่ radiusd รันภายใต้ owner, group ที่ชื่อ radiusd ทำให้ไม่สามารถอ่านไฟล์ ที่ root สร้างขึ้นได้</p>
<p>ใช้คำสั่ง ls เพื่อตรวจสอบไฟล์ที่ root สร้างขึ้น</p>
<pre>[root@fc11-64a certs]# <strong>ls -lrt
</strong>total 108
-rw-r----- 1 root radiusd  578 2009-09-15 22:29 xpextensions
-rw-r----- 1 root radiusd 1123 2009-09-15 22:29 server.cnf
-rw-r----- 1 root radiusd 7819 2009-09-15 22:29 README
-rw-r----- 1 root radiusd 4302 2009-09-15 22:29 Makefile
-rw-r----- 1 root radiusd 1109 2009-09-15 22:29 client.cnf
-rw-r----- 1 root radiusd 1288 2009-09-15 22:29 ca.cnf
-rwxr-x--- 1 root radiusd 2072 2009-09-15 22:29 bootstrap
-rw-r----- 1 root root     245 2009-11-28 12:20 dh
-rw-r----- 1 root root    5120 2009-11-28 12:20 random
-rw-r----- 1 root root    1751 2009-11-28 12:20 server.key
-rw-r----- 1 root root    1062 2009-11-28 12:20 server.csr
-rw-r----- 1 root root    1743 2009-11-28 12:20 ca.key
-rw-r----- 1 root root    1675 2009-11-28 12:20 ca.pem
-rw-r----- 1 root root       0 2009-11-28 12:20 index.txt.old
-rw-r----- 1 root root       3 2009-11-28 12:20 serial.old
-rw-r----- 1 root root       3 2009-11-28 12:20 serial
-rw-r----- 1 root root      21 2009-11-28 12:20 index.txt.attr
-rw-r----- 1 root root     120 2009-11-28 12:20 index.txt
-rw-r----- 1 root root    4210 2009-11-28 12:20 server.crt
-rw-r----- 1 root root    4210 2009-11-28 12:20 01.pem
-rw-r----- 1 root root    2533 2009-11-28 12:20 server.p12
<span style="color: #ff0000;">-rw-r----- 1 root root    3503 2009-11-28 12:20 server.pem
</span>-rw-r----- 1 root root    1195 2009-11-28 12:20 ca.der</pre>
<p>การแก้ไขปัญหา ทำได้โดยการเปลี่ยน permission ของไฟล์ เพื่อให้ radiusd สามารถอ่านไฟล์ได้ ในที่นี้เปลี่ยนแค่ group ของไฟล์ก็เพียงพอแล้ว และเพื่อความปลอดภัยของระบบด้วย</p>
<p>ใช้คำสั่ง chgrp เพื่อเปลี่ยน group ของไฟล์</p>
<pre>[root@fc11-64a certs]# <strong>chgrp radiusd *
</strong>[root@fc11-64a certs]# <strong>ls -lrt
</strong>total 108
-rw-r----- 1 root radiusd  578 2009-09-15 22:29 xpextensions
-rw-r----- 1 root radiusd 1123 2009-09-15 22:29 server.cnf
-rw-r----- 1 root radiusd 7819 2009-09-15 22:29 README
-rw-r----- 1 root radiusd 4302 2009-09-15 22:29 Makefile
-rw-r----- 1 root radiusd 1109 2009-09-15 22:29 client.cnf
-rw-r----- 1 root radiusd 1288 2009-09-15 22:29 ca.cnf
-rwxr-x--- 1 root radiusd 2072 2009-09-15 22:29 bootstrap
-rw-r----- 1 root radiusd  245 2009-11-28 12:20 dh
-rw-r----- 1 root radiusd 5120 2009-11-28 12:20 random
-rw-r----- 1 root radiusd 1751 2009-11-28 12:20 server.key
-rw-r----- 1 root radiusd 1062 2009-11-28 12:20 server.csr
-rw-r----- 1 root radiusd 1743 2009-11-28 12:20 ca.key
-rw-r----- 1 root radiusd 1675 2009-11-28 12:20 ca.pem
-rw-r----- 1 root radiusd    0 2009-11-28 12:20 index.txt.old
-rw-r----- 1 root radiusd    3 2009-11-28 12:20 serial.old
-rw-r----- 1 root radiusd    3 2009-11-28 12:20 serial
-rw-r----- 1 root radiusd   21 2009-11-28 12:20 index.txt.attr
-rw-r----- 1 root radiusd  120 2009-11-28 12:20 index.txt
-rw-r----- 1 root radiusd 4210 2009-11-28 12:20 server.crt
-rw-r----- 1 root radiusd 4210 2009-11-28 12:20 01.pem
-rw-r----- 1 root radiusd 2533 2009-11-28 12:20 server.p12
<span style="color: #0000ff;">-rw-r----- 1 root radiusd 3503 2009-11-28 12:20 server.pem
</span>-rw-r----- 1 root radiusd 1195 2009-11-28 12:20 ca.der</pre>
<p>ใช้คำสั่ง service เพื่อรันเซอร์วิส radiusd อีกครั้ง</p>
<pre>[root@fc11-64a certs]# <strong>service radiusd start
</strong>Starting RADIUS server:                                    [  OK  ]</pre>
<p>ครั้งนี้จะสามารถรันได้ [ OK ] หากดูในไฟล์ radius.log จะมีข้อความดังนี้เกิดขึ้น</p>
<pre>[root@fc11-64a ~]# <strong>tail /var/log/radius/radius.log
</strong>...
Sat Nov 28 12:23:10 2009 : Info: Loaded virtual server inner-tunnel
Sat Nov 28 12:23:11 2009 : Info: Loaded virtual server &lt;default&gt;
Sat Nov 28 12:23:11 2009 : Info: Ready to process requests.</pre>
<p>ใช้คำสั่ง ps เพื่อ ตรวจสอบ process ของ radiusd</p>
<pre>[root@fc11-64a certs]# <strong>ps -ef | grep radiusd
</strong>radiusd   1772     1  0 12:23 ?        00:00:00 /usr/sbin/radiusd
root      1783  1393  0 12:23 pts/0    00:00:00 grep radiusd</pre>
<p>ใช้คำสั่ง netstat เพื่อตรวจสอบพอร์ตของ radiusd ที่ใช้</p>
<pre>[root@fc11-64a raddb]# <strong>netstat -a | grep udp
</strong>...
udp        0      0 *:radius                    *:*
udp        0      0 *:radius-acct               *:*
udp        0      0 *:tdp-suite                 *:*</pre>
<p>โดยดีฟอลต์ของ FreeRADIUS จะใช้พอร์ต UDP 1812, 1813, 1814 ในการทำงาน</p>
<p>ดูการ map ชื่อพอร์ตและเลขหมายของพอร์ตในไฟล์ /etc/services</p>
<pre>[root@fc11-64a ~]# <strong>cat /etc/services
</strong>...
radius          1812/udp                        # Radius
radius-acct     1813/udp        radacct         # Radius Accounting
tdp-suite       1814/udp                # TDP Suite</pre>
<h4>ทดสอบด้วย radtest</h4>
<p>จากการติดตั้ง freeradius-utils จะมีโปรแกรม radius client มาให้ด้วย คำสั่งหนึ่งที่ใช้ในการทดสอบอย่างง่ายๆ คือ radtest</p>
<pre>[root@fc11-64a ~]# <strong>radtest</strong>
Usage: radtest user passwd radius-server[:port] nas-port-number secret [ppphint] [nasname]</pre>
<p>พารามิเตอร์ที่ต้องระบุในการใช้คำสั่ง radtest คือ</p>
<ul>
<li>user                              ชื่อ username ที่ต้องการ authenticate</li>
<li>passwd                        รหัสผ่าน password สำหรับ username</li>
<li>radius-server            เป็น IP Address ของเครื่องที่รัน radiusd ทำหน้าที่เป็น RADIUS Server</li>
<li>nas-port-number    ระบุหมายเลขพอร์ต สำหรับการทดสอบจะใช้เป็นตัวเลขอะไรก็ได้</li>
<li>secret                           เป็น shared secret เพื่อต้องระบุใน RADIUS Server เพื่อเป็นการอนุญาตว่า เครื่อง RADIUS Client ใดสามารถมา authenticate ได้บ้าง</li>
</ul>
<p>ทดสอบการส่ง user, password ไปยัง radius server ที่ติดตั้ง ในที่นนี้ทดสอบบนเครื่องเดียวกัน ระบุเป็น 127.0.0.1</p>
<pre>[root@fc11-64a ~]# <strong>radtest user1 password1 127.0.0.1 1 secret1
</strong>Sending Access-Request of id 207 to 127.0.0.1 port 1812
        User-Name = "user1"
        User-Password = "password1"
        NAS-IP-Address = 192.168.1.1
        NAS-Port = 1
rad_recv: <strong><span style="color: #ff0000;">Access-Reject</span></strong> packet from host 127.0.0.1 port 1812, id=207, length=20
rad_verify: Received Access-Reject packet from client 127.0.0.1 port 1812 with invalid signature (err=2)!  (<span style="color: #ff0000;">Shared secret is incorrect.</span>)
Sending Access-Request of id 207 to 127.0.0.1 port 1812
        User-Name = "user1"
        User-Password = "password1"
        NAS-IP-Address = 192.168.1.1
        NAS-Port = 1
rad_recv: Access-Reject packet from host 127.0.0.1 port 1812, id=207, length=20
rad_verify: Received Access-Reject packet from client 127.0.0.1 port 1812 with invalid signature (err=2)!  (Shared secret is incorrect.)
Sending Access-Request of id 207 to 127.0.0.1 port 1812
        User-Name = "user1"
        User-Password = "password1"
        NAS-IP-Address = 192.168.1.1
        NAS-Port = 1
rad_recv: Access-Reject packet from host 127.0.0.1 port 1812, id=207, length=20
rad_verify: Received Access-Reject packet from client 127.0.0.1 port 1812 with invalid signature (err=2)!  (Shared secret is incorrect.)
radclient: no response from server for ID 207 socket 3</pre>
<p>ผลจากการรันคำสั่ง radtest จะฟ้อง &#8220;Access-Reject&#8221; เนื่องจาก &#8220;Shared secret is incorrect&#8221;</p>
<p>การแก้ไข คือต้องระบุ shared secret ให้ถูกต้อง</p>
<p>ในไฟล์ /etc/raddb/clients.conf จะมีคอนฟิกระบุ เครื่อง client ที่สามารถส่งข้อมูลมา authenticate ได้ แต่ต้องระบุ shared secret ให้ถูกต้อง</p>
<p>หากตัดส่วน comment &#8221;#&#8221; ออก ดีฟอลต์จากการติดตั้ง จะมีคอนฟิกสำหรับเครื่อง localhost ดังนี้</p>
<pre>client localhost {
    ipaddr = 127.0.0.1
    secret      = testing123
    require_message_authenticator = no
    nastype     = other
}</pre>
<p>จากคอนฟิก แปลว่าหากมีการส่ง request จากเครื่อง localhost หรือ 127.0.01 ต้องระบุ shared secret เป็น testing123 จึงจะใช้ server ได้</p>
<p>ทดสอบคำสั่ง radtest ด้วย shared secret ที่ถูกต้อง</p>
<pre>[root@fc11-64a ~]# <strong>radtest user1 password1 127.0.0.1 1 testing123
</strong>Sending Access-Request of id 58 to 127.0.0.1 port 1812
        User-Name = "user1"
        User-Password = "password1"
        NAS-IP-Address = 192.168.1.1
        NAS-Port = 1
rad_recv: <span style="color: #ff0000;">Access-Reject packet</span> from host 127.0.0.1 port 1812, id=58, length=20</pre>
<p>ผลการรันยังคงได้เป็น &#8220;Access-Reject&#8221; อยู่ เนื่องจาก ไม่มี username ที่ใช้ใน Server</p>
<p>ดีฟอลต์คอนฟิกเบื้องต้น จะเก็บไฟล์ username, password ไว้ในไฟล์ /etc/raddb/users โดยมีบรรทัดสุดท้ายอธิบายว่า ถ้าไม่ match หรือไม่มี username, password ที่คอนฟิกไว้ จะ denied การใช้งาน</p>
<p># On no match, the user is denied access.</p>
<p>แก้ไขไฟล์ /etc/raddb/users โดยเพิ่ม username, password ที่ต้องการ</p>
<pre>...
<span style="color: #0000ff;">user1  Cleartext-Password := "password1"
       Reply-Message = "Hello, %{User-Name}"</span></pre>
<pre># On no match, the user is denied access.</pre>
<p>ใช้คำสั่ง service เพื่อรีโหลดคอนฟิกของ radius ใหม่</p>
<pre>[root@fc11-64a ~]# <strong>service radiusd reload
</strong>Reloading RADIUS server:                                   [  OK  ]</pre>
<p>ทดสอบคำสั่ง radtest โดยระบุ user, password ที่ถูกต้องจากไฟล์ /etc/raddb/users จะได้รับ &#8220;Access-Accept&#8221;</p>
<pre>[root@fc11-64a raddb]# <strong>radtest user1 password1 127.0.0.1 1 testing123
</strong>Sending Access-Request of id 49 to 127.0.0.1 port 1812
        User-Name = "user1"
        User-Password = "password1"
        NAS-IP-Address = 192.168.1.1
        NAS-Port = 1
rad_recv: <strong><span style="color: #0000ff;">Access-Accept</span></strong> packet from host 127.0.0.1 port 1812, id=49, length=34
<span style="color: #0000ff;">        Reply-Message = "Hello, user1"</span></pre>
<p>ทดสอบด้วย user ที่มีอยู่ในไฟล์ /etc/raddb/users แต่ระบุ password ผิด จะได้รับ &#8220;Access-Reject&#8221; แต่จะได้ &#8220;Reply-Message&#8221; ของ username นั้น กลับมาด้วย</p>
<pre>[root@fc11-64a raddb]# <strong>radtest user1 password2 127.0.0.1 1 testing123
</strong>Sending Access-Request of id 76 to 127.0.0.1 port 1812
        User-Name = "user1"
        User-Password = "password2"
        NAS-IP-Address = 192.168.1.1
        NAS-Port = 1
rad_recv: <span style="color: #ff0000;"><strong>Access-Reject</strong></span> packet from host 127.0.0.1 port 1812, id=76, length=34
<span style="color: #0000ff;">        Reply-Message = "Hello, user1"</span></pre>
<p>ทดสอบด้วย user ที่ไม่มีอยู่ในไฟล์ /etc/raddb/users  จะได้รับ &#8220;Access-Reject&#8221;</p>
<pre>[root@fc11-64a raddb]# <strong>radtest user2 password2 127.0.0.1 1 testing123
</strong>Sending Access-Request of id 91 to 127.0.0.1 port 1812
        User-Name = "user2"
        User-Password = "password2"
        NAS-IP-Address = 192.168.1.1
        NAS-Port = 1
rad_recv: <span style="color: #ff0000;"><strong>Access-Reject </strong></span>packet from host 127.0.0.1 port 1812, id=91, length=20</pre>
<h4>รัน radiusd ในโหมด debug</h4>
<p>เมื่อเกิดปัญหาการคอนฟิกหรือการทำงานของ FreeRADIUS สิ่งหนึ่งที่ช่วยทำให้สามารถตรวจสอบรายละเอียดและแก้ไขปัญหาที่เกิดขึ้นได้ คือรัน radiusd ในโหมด debug ซึ่งหน้าจอจะแสดงขั้นตอนการทำงานของ radiusd อย่างละเอียด ทำให้เราสามารถทราบได้ว่า ปัญหาเกิดขึ้นที่จุดไหน</p>
<p>ใช้คำสั่ง service เพื่อหยุดรัน radiusd ในโหมดปกติ</p>
<pre>[root@fc11-64a ~]# <strong>service radiusd stop
</strong>Stopping RADIUS server:                                    [  OK  ]</pre>
<p>รันคำสั่ง radiusd ตามด้วย ออปชั่น &#8216;-X&#8217; เพื่อรันในโหมด debug หน้าจอจะแสดงรายละเอียดในการทำงานของ radiusd สังเกตว่าเมื่อรันโหมด debug จะไม่กลับคืนสู่ prompt</p>
<p>หากต้องการหยุดรันในโหมด debug สามารถทำได้โดยกด [Ctrl-C]</p>
<p>ตัวอย่างการรัน radiusd ในโหมด debug</p>
<pre>[root@fc11-64a ~]# <strong>radiusd -X
</strong>FreeRADIUS Version 2.1.7, for host x86_64-redhat-linux-gnu, built on Sep 15 2009 at 11:29:29
Copyright (C) 1999-2009 The FreeRADIUS server project and contributors.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
You may redistribute copies of FreeRADIUS under the terms of the
GNU General Public License v2.
Starting - reading configuration files ...
including configuration file /etc/raddb/radiusd.conf
including configuration file /etc/raddb/proxy.conf
including configuration file /etc/raddb/clients.conf
including files in directory /etc/raddb/modules/
including configuration file /etc/raddb/modules/acct_unique
including configuration file /etc/raddb/modules/always
including configuration file /etc/raddb/modules/attr_filter
including configuration file /etc/raddb/modules/attr_rewrite
including configuration file /etc/raddb/modules/chap
including configuration file /etc/raddb/modules/checkval
including configuration file /etc/raddb/modules/counter
including configuration file /etc/raddb/modules/cui
including configuration file /etc/raddb/modules/detail
including configuration file /etc/raddb/modules/detail.example.com
including configuration file /etc/raddb/modules/detail.log
including configuration file /etc/raddb/modules/digest
including configuration file /etc/raddb/modules/echo
including configuration file /etc/raddb/modules/etc_group
including configuration file /etc/raddb/modules/exec
including configuration file /etc/raddb/modules/expiration
including configuration file /etc/raddb/modules/expr
including configuration file /etc/raddb/modules/files
including configuration file /etc/raddb/modules/inner-eap
including configuration file /etc/raddb/modules/ippool
including configuration file /etc/raddb/modules/linelog
including configuration file /etc/raddb/modules/logintime
including configuration file /etc/raddb/modules/mac2ip
including configuration file /etc/raddb/modules/mac2vlan
including configuration file /etc/raddb/modules/mschap
including configuration file /etc/raddb/modules/otp
including configuration file /etc/raddb/modules/pam
including configuration file /etc/raddb/modules/pap
including configuration file /etc/raddb/modules/passwd
including configuration file /etc/raddb/modules/perl
including configuration file /etc/raddb/modules/policy
including configuration file /etc/raddb/modules/preprocess
including configuration file /etc/raddb/modules/radutmp
including configuration file /etc/raddb/modules/realm
including configuration file /etc/raddb/modules/smbpasswd
including configuration file /etc/raddb/modules/smsotp
including configuration file /etc/raddb/modules/sql_log
including configuration file /etc/raddb/modules/sqlcounter_expire_on_login
including configuration file /etc/raddb/modules/sradutmp
including configuration file /etc/raddb/modules/unix
including configuration file /etc/raddb/modules/wimax
including configuration file /etc/raddb/eap.conf
including configuration file /etc/raddb/policy.conf
including files in directory /etc/raddb/sites-enabled/
including configuration file /etc/raddb/sites-enabled/control-socket
including configuration file /etc/raddb/sites-enabled/default
including configuration file /etc/raddb/sites-enabled/inner-tunnel
group = radiusd
user = radiusd
including dictionary file /etc/raddb/dictionary
main {
        prefix = "/usr"
        localstatedir = "/var"
        logdir = "/var/log/radius"
        libdir = "/usr/lib64/freeradius"
        radacctdir = "/var/log/radius/radacct"
        hostname_lookups = no
        max_request_time = 30
        cleanup_delay = 5
        max_requests = 1024
        allow_core_dumps = no
        pidfile = "/var/run/radiusd/radiusd.pid"
        checkrad = "/usr/sbin/checkrad"
        debug_level = 0
        proxy_requests = yes
 log {
        stripped_names = no
        auth = no
        auth_badpass = no
        auth_goodpass = no
 }
 security {
        max_attributes = 200
        reject_delay = 1
        status_server = yes
 }
}
radiusd: #### Loading Realms and Home Servers ####
 proxy server {
        retry_delay = 5
        retry_count = 3
        default_fallback = no
        dead_time = 120
        wake_all_if_all_dead = no
 }
 home_server localhost {
        ipaddr = 127.0.0.1
        port = 1812
        type = "auth"
        secret = "testing123"
        response_window = 20
        max_outstanding = 65536
        require_message_authenticator = no
        zombie_period = 40
        status_check = "status-server"
        ping_interval = 30
        check_interval = 30
        num_answers_to_alive = 3
        num_pings_to_alive = 3
        revive_interval = 120
        status_check_timeout = 4
        irt = 2
        mrt = 16
        mrc = 5
        mrd = 30
 }
 home_server_pool my_auth_failover {
        type = fail-over
        home_server = localhost
 }
 realm example.com {
        auth_pool = my_auth_failover
 }
 realm LOCAL {
 }
radiusd: #### Loading Clients ####
 client localhost {
        ipaddr = 127.0.0.1
        require_message_authenticator = no
        secret = "testing123"
        nastype = "other"
 }
radiusd: #### Instantiating modules ####
 instantiate {
 Module: Linked to module rlm_exec
 Module: Instantiating exec
  exec {
        wait = no
        input_pairs = "request"
        shell_escape = yes
  }
 Module: Linked to module rlm_expr
 Module: Instantiating expr
 Module: Linked to module rlm_expiration
 Module: Instantiating expiration
  expiration {
        reply-message = "Password Has Expired  "
  }
 Module: Linked to module rlm_logintime
 Module: Instantiating logintime
  logintime {
        reply-message = "You are calling outside your allowed timespan  "
        minimum-timeout = 60
  }
 }
radiusd: #### Loading Virtual Servers ####
server inner-tunnel {
 modules {
 Module: Checking authenticate {...} for more modules to load
 Module: Linked to module rlm_pap
 Module: Instantiating pap
  pap {
        encryption_scheme = "auto"
        auto_header = no
  }
 Module: Linked to module rlm_chap
 Module: Instantiating chap
 Module: Linked to module rlm_mschap
 Module: Instantiating mschap
  mschap {
        use_mppe = yes
        require_encryption = no
        require_strong = no
        with_ntdomain_hack = no
  }
 Module: Linked to module rlm_unix
 Module: Instantiating unix
  unix {
        radwtmp = "/var/log/radius/radwtmp"
  }
 Module: Linked to module rlm_eap
 Module: Instantiating eap
  eap {
        default_eap_type = "md5"
        timer_expire = 60
        ignore_unknown_eap_types = no
        cisco_accounting_username_bug = no
        max_sessions = 2048
  }
 Module: Linked to sub-module rlm_eap_md5
 Module: Instantiating eap-md5
 Module: Linked to sub-module rlm_eap_leap
 Module: Instantiating eap-leap
 Module: Linked to sub-module rlm_eap_gtc
 Module: Instantiating eap-gtc
   gtc {
        challenge = "Password: "
        auth_type = "PAP"
   }
 Module: Linked to sub-module rlm_eap_tls
 Module: Instantiating eap-tls
   tls {
        rsa_key_exchange = no
        dh_key_exchange = yes
        rsa_key_length = 512
        dh_key_length = 512
        verify_depth = 0
        pem_file_type = yes
        private_key_file = "/etc/raddb/certs/server.pem"
        certificate_file = "/etc/raddb/certs/server.pem"
        CA_file = "/etc/raddb/certs/ca.pem"
        private_key_password = "whatever"
        dh_file = "/etc/raddb/certs/dh"
        random_file = "/etc/raddb/certs/random"
        fragment_size = 1024
        include_length = yes
        check_crl = no
        cipher_list = "DEFAULT"
        make_cert_command = "/etc/raddb/certs/bootstrap"
    cache {
        enable = no
        lifetime = 24
        max_entries = 255
    }
   }
 Module: Linked to sub-module rlm_eap_ttls
 Module: Instantiating eap-ttls
   ttls {
        default_eap_type = "md5"
        copy_request_to_tunnel = no
        use_tunneled_reply = no
        virtual_server = "inner-tunnel"
        include_length = yes
   }
 Module: Linked to sub-module rlm_eap_peap
 Module: Instantiating eap-peap
   peap {
        default_eap_type = "mschapv2"
        copy_request_to_tunnel = no
        use_tunneled_reply = no
        proxy_tunneled_request_as_eap = yes
        virtual_server = "inner-tunnel"
   }
 Module: Linked to sub-module rlm_eap_mschapv2
 Module: Instantiating eap-mschapv2
   mschapv2 {
        with_ntdomain_hack = no
   }
 Module: Checking authorize {...} for more modules to load
 Module: Linked to module rlm_realm
 Module: Instantiating suffix
  realm suffix {
        format = "suffix"
        delimiter = "@"
        ignore_default = no
        ignore_null = no
  }
 Module: Linked to module rlm_files
 Module: Instantiating files
  files {
        usersfile = "/etc/raddb/users"
        acctusersfile = "/etc/raddb/acct_users"
        preproxy_usersfile = "/etc/raddb/preproxy_users"
        compat = "no"
  }
 Module: Checking session {...} for more modules to load
 Module: Linked to module rlm_radutmp
 Module: Instantiating radutmp
  radutmp {
        filename = "/var/log/radius/radutmp"
        username = "%{User-Name}"
        case_sensitive = yes
        check_with_nas = yes
        perm = 384
        callerid = yes
  }
 Module: Checking post-proxy {...} for more modules to load
 Module: Checking post-auth {...} for more modules to load
 Module: Linked to module rlm_attr_filter
 Module: Instantiating attr_filter.access_reject
  attr_filter attr_filter.access_reject {
        attrsfile = "/etc/raddb/attrs.access_reject"
        key = "%{User-Name}"
  }
 } # modules
} # server
server {
 modules {
 Module: Checking authenticate {...} for more modules to load
 Module: Checking authorize {...} for more modules to load
 Module: Linked to module rlm_preprocess
 Module: Instantiating preprocess
  preprocess {
        huntgroups = "/etc/raddb/huntgroups"
        hints = "/etc/raddb/hints"
        with_ascend_hack = no
        ascend_channels_per_line = 23
        with_ntdomain_hack = no
        with_specialix_jetstream_hack = no
        with_cisco_vsa_hack = no
        with_alvarion_vsa_hack = no
  }
 Module: Checking preacct {...} for more modules to load
 Module: Linked to module rlm_acct_unique
 Module: Instantiating acct_unique
  acct_unique {
        key = "User-Name, Acct-Session-Id, NAS-IP-Address, Client-IP-Address, NAS-Port"
  }
 Module: Checking accounting {...} for more modules to load
 Module: Linked to module rlm_detail
 Module: Instantiating detail
  detail {
        detailfile = "/var/log/radius/radacct/%{Client-IP-Address}/detail-%Y%m%d"
        header = "%t"
        detailperm = 384
        dirperm = 493
        locking = no
        log_packet_header = no
  }
 Module: Instantiating attr_filter.accounting_response
  attr_filter attr_filter.accounting_response {
        attrsfile = "/etc/raddb/attrs.accounting_response"
        key = "%{User-Name}"
  }
 Module: Checking session {...} for more modules to load
 Module: Checking post-proxy {...} for more modules to load
 Module: Checking post-auth {...} for more modules to load
 } # modules
} # server
radiusd: #### Opening IP addresses and Ports ####
listen {
        type = "auth"
        ipaddr = *
        port = 0
}
listen {
        type = "acct"
        ipaddr = *
        port = 0
}
listen {
        type = "control"
 listen {
        socket = "/var/run/radiusd/radiusd.sock"
 }
}
Listening on authentication address * port 1812
Listening on accounting address * port 1813
Listening on command file /var/run/radiusd/radiusd.sock
Listening on proxy address * port 1814
Ready to process requests.</pre>
<p>ตัวอย่างการรัน radtest และ ข้อความในหน้าจอโหมด debug ที่แสดง</p>
<pre>[root@fc11-64a raddb]# <strong>radtest user1 password1 127.0.0.1 1 testing123
</strong>Sending Access-Request of id 118 to 127.0.0.1 port 1812
        User-Name = "user1"
        User-Password = "password1"
        NAS-IP-Address = 192.168.1.1
        NAS-Port = 1
rad_recv: Access-Accept packet from host 127.0.0.1 port 1812, id=118, length=34
        Reply-Message = "Hello, user1"</pre>
<p>หน้าจอโหมด debug ที่แสดง พร้อมเน้นข้อความที่เกี่ยวข้องกับการทำงานของ radiusd เมื่อได้รับการ request จากการรันคำสั่ง radtest แบบคร่าวๆ</p>
<pre>rad_recv: <span style="color: #0000ff;">Access-Request </span>packet from host 127.0.0.1 port 53435, id=118, length=57
<span style="color: #0000ff;">        User-Name = "user1"
</span><span style="color: #0000ff;">        User-Password = "password1"
        NAS-IP-Address = 192.168.1.1
        NAS-Port = 1
</span>+- entering group authorize {...}
++[preprocess] returns ok
++[chap] returns noop
++[mschap] returns noop
[suffix] <span style="color: #0000ff;">No '@' in User-Name = "user1", looking up realm NULL
</span>[suffix] No such realm "NULL"
++[suffix] returns noop
[eap] <span style="color: #0000ff;">No EAP-Message, not doing EAP
</span>++[eap] returns noop
++[unix] returns notfound
[files] <span style="color: #0000ff;">users: Matched entry user1 at line 203
</span>[files]         <span style="color: #0000ff;">expand: Hello, %{User-Name} -&gt; Hello, user1
</span>++[files] <span style="color: #0000ff;">returns ok
</span>++[expiration] returns noop
++[logintime] returns noop
++[pap] returns updated
Found Auth-Type = PAP
+- entering group PAP {...}
[pap] login attempt with password "password1"
[pap] <span style="color: #0000ff;">Using clear text password "password1"
</span>[pap] <span style="color: #0000ff;">User authenticated successfully
</span>++[pap] <span style="color: #0000ff;">returns ok
</span>+- entering group post-auth {...}
++[exec] returns noop
<span style="color: #0000ff;">Sending Access-Accept of id 118 to 127.0.0.1 port 53435
        Reply-Message = "Hello, user1"
</span>Finished request 0.
Going to the next request
Waking up in 4.9 seconds.
Cleaning up request 0 ID 118 with timestamp +58
Ready to process requests.</pre>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li><a href="http://freeradius.org/" target="_blank">FreeRADIUS: The world&#8217;s most popular RADIUS Server</a></li>
<li><a href="http://mirrors.kernel.org/fedora/updates/11/x86_64/" target="_blank">Fedora 11 x86_64 updates</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2009/11/basic_install_freeradius/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>แก้ไขคอนฟิก iptables firewall rule</title>
		<link>http://spalinux.com/2009/07/customize_iptables_firewall_rules</link>
		<comments>http://spalinux.com/2009/07/customize_iptables_firewall_rules#comments</comments>
		<pubDate>Sat, 18 Jul 2009 06:40:45 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Firewall]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[iptables]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=842</guid>
		<description><![CDATA[การติดตั้งลีนุกซ์ส่วนใหญ่รวมทั้ง fedora จะติดตั้ง และเปิดคุณสมบัติ firewall มาด้วย ซึ่งโดยดีฟอลต์แล้ว จะอนุญาตให้ packet ขาเข้า (INPUT) ได้เฉพาะ ping และ SSH เท่านั้น ลีนุกซ์จะใช้โปรแกรมที่ชื่อ iptables ทำหน้าที่เป็น firewall และใช้คำสั่งนี้ในการแสดงและแก้ไขคอนฟิก (rules) ของ firewall ตัวอย่างการใช้คำสั่ง iptables เพื่อแสดง rule [root@fc11-64min ~]# iptables -L -v Chain INPUT (policy ACCEPT 0 packets, 0 bytes)  pkts bytes target     prot opt in     out     source               destination    42  2148 ACCEPT     all  [...]]]></description>
			<content:encoded><![CDATA[<p>การติดตั้งลีนุกซ์ส่วนใหญ่รวมทั้ง fedora จะติดตั้ง และเปิดคุณสมบัติ firewall มาด้วย ซึ่งโดยดีฟอลต์แล้ว จะอนุญาตให้ packet ขาเข้า (INPUT) ได้เฉพาะ ping และ SSH เท่านั้น</p>
<p>ลีนุกซ์จะใช้โปรแกรมที่ชื่อ iptables ทำหน้าที่เป็น firewall และใช้คำสั่งนี้ในการแสดงและแก้ไขคอนฟิก (rules) ของ firewall</p>
<p><span id="more-842"></span></p>
<p>ตัวอย่างการใช้คำสั่ง iptables เพื่อแสดง rule</p>
<pre>[root@fc11-64min ~]# <strong>iptables -L -v
</strong>Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
   42  2148 ACCEPT     all  --  any    any     anywhere             anywhere            state RELATED,ESTABLISHED
<span style="color: #0000ff;">    0     0 ACCEPT     icmp --  any    any     anywhere             anywhere
</span>    0     0 ACCEPT     all  --  lo     any     anywhere             anywhere
<span style="color: #0000ff;">    0     0 ACCEPT     tcp  --  any    any     anywhere             anywhere            state NEW tcp dpt:ssh
</span>    0     0 REJECT     all  --  any    any     anywhere             anywhere            reject-with icmp-host-prohibited</pre>
<pre>Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
    0     0 REJECT     all  --  any    any     anywhere             anywhere            reject-with icmp-host-prohibited</pre>
<pre>Chain OUTPUT (policy ACCEPT 63 packets, 7412 bytes)
 pkts bytes target     prot opt in     out     source               destination</pre>
<p>ถ้าเราติดตั้งและคอนฟิกโปรแกรมเพิ่มเติมบนเครื่องนี้ เช่น ลงเว็บเซิร์ฟเวอร์ จะทำให้ไม่สามารถเรียกมาจากเครื่องอื่นๆ ได้ นอกจากต้องแก้ไขคอนฟิกของ firewalll ก่อน</p>
<p>บน Fedora จะมี script ชื่อ system-config-firewall-tui ช่วยในการคอนฟิกของ iptables เช่น ถ้าต้องการอนุญาตให้ เครื่องอื่นสามารถเรียกเว็บเซิร์ฟเวอร์ที่รันพอร์ตดีฟอลต์ http (TCP 80) ได้ ต้องแก้ไขดังนี้</p>
<pre>[root@fc11-64min ~]# <strong>system-config-firewall-tui</strong></pre>
<pre>                                      ┌────────────┤ Firewall Configuration ├────────────┐
                                      │                                                  │
                                      │ A firewall protects against unauthorized         │
                                      │ network intrusions. Enabling a firewall blocks   │
                                      │ all incoming connections. Disabling a firewall   │
                                      │ allows all connections and is not recommended.   │
                                      │                                                  │
                                      │              Firewall: [*] Enabled               │
                                      │                                                  │
                                      │    ┌────┐      ┌───────────┐      ┌────────┐     │
                                      │    │ OK │      │ <strong><span style="color: #0000ff;">Customize</span></strong> │      │ Cancel │     │
                                      │    └────┘      └───────────┘      └────────┘     │
                                      │                                                  │
                                      │                                                  │
                                      └──────────────────────────────────────────────────┘</pre>
<p>กด [tab] เพื่อเลื่อนไปที่ &#8220;Customize&#8221;</p>
<pre>                                 ┌───────────────────┤ Trusted Services ├────────────────────┐
                                 │                                                           │
                                 │ Here you can define which services are trusted. Trusted   │
                                 │ services are accessible from all hosts and networks.      │
                                 │                                                           │
                                 │           [ ] RADIUS                        ↑             │
                                 │           [*] SSH                           ▒             │
                                 │           [ ] Samba                         ▒             │
                                 │           [ ] Samba Client                  ▒             │
                                 │           [ ] Secure WWW (HTTPS)            ▮             │
                                 │           <strong><span style="color: #0000ff;">[*] WWW (HTTP)</span></strong>                    ↓             │
                                 │                                                           │
                                 │                                 ┌─────────┐   ┌───────┐   │
                                 │                                 │ Forward │   │ <strong><span style="color: #0000ff;">Close</span></strong> │   │
                                 │                                 └─────────┘   └───────┘   │
                                 │                                                           │
                                 │                                                           │
                                 └───────────────────────────────────────────────────────────┘</pre>
<p>ในหน้า &#8220;Trusted Services&#8221; กดปุ่มลูกศรเพื่อเลื่อนลงมาบรรทัด [x] WWW (HTTP) แล้วกดปุ่ม [space-bar] เพื่อเลือก แล้วกด &#8220;Close&#8221;</p>
<p>หน้าจอจะขึ้นถามให้ บันทึกคอนฟิกใหม่ เลือก [Yes]</p>
<pre>                                         ┌────────────────┤ Warning ├─────────────────┐
                                         │                                            │
                                         │ Clicking the 'Yes' button will override    │
                                         │ any existing firewall configuration. Are   │
                                         │ you sure that you want to do this?         │
                                         │                                            │
                                         │ Please remember to check if the services   │
                                         │ iptables and ip6tables are enabled.        │
                                         │                                            │
                                         │        ┌─────┐              ┌────┐         │
                                         │        │ <strong><span style="color: #0000ff;">Yes</span></strong> │              │ No │         │
                                         │        └─────┘              └────┘         │
                                         │                                            │
                                         │                                            │
                                         └────────────────────────────────────────────┘</pre>
<p>ใช้คำสั่ง iptables อีกครั้ง เพื่อแสดงคอนฟิก firewall ปัจจุบัน หลังการแก้ไข</p>
<pre>[root@fc11-64min ~]# <strong>iptables -L -v
</strong>Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
   11   752 ACCEPT     all  --  any    any     anywhere             anywhere            state RELATED,ESTABLISHED
    0     0 ACCEPT     icmp --  any    any     anywhere             anywhere
    0     0 ACCEPT     all  --  lo     any     anywhere             anywhere
    0     0 ACCEPT     tcp  --  any    any     anywhere             anywhere            state NEW tcp dpt:ssh
<span style="color: #0000ff;"><strong>    0     0 ACCEPT     tcp  --  any    any     anywhere             anywhere            state NEW tcp dpt:http
</strong></span>    0     0 REJECT     all  --  any    any     anywhere             anywhere            reject-with icmp-host-prohibited</pre>
<pre>Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
    0     0 REJECT     all  --  any    any     anywhere             anywhere            reject-with icmp-host-prohibited</pre>
<pre>Chain OUTPUT (policy ACCEPT 10 packets, 1072 bytes)
 pkts bytes target     prot opt in     out     source               destination</pre>
<p>หลังจากอนุญาต http แล้ว ตอนนี้เครื่องอื่น ก็สามารถเรียกเว็บเซิร์ฟเวอร์ที่รันบนเครื่องนี้ได้แล้ว</p>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2009/07/customize_iptables_firewall_rules/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>เพิ่มความปลอดภัยให้ Solaris 10 แบบง่าย</title>
		<link>http://spalinux.com/2009/05/basic_secure_solaris_10</link>
		<comments>http://spalinux.com/2009/05/basic_secure_solaris_10#comments</comments>
		<pubDate>Sat, 23 May 2009 14:55:46 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Performance]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Solaris]]></category>
		<category><![CDATA[X Window]]></category>
		<category><![CDATA[solaris 10]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=681</guid>
		<description><![CDATA[วันนี้ขอเขียนเกี่ยวกับ Solaris 10 ซะหน่อย ช่วงนี้ได้รับมอบหมายให้เพิ่มความปลอดภัย (secure) ให้กับเครื่อง Solaris  แต่มีข้อแม้ไม่อยากให้ลง JASS (Solaris Security Toolkit) ก็เลยลองทำดู และเรียบเรียงมาเป็นบทความให้ผู้สนใจทั่วไป การเพิ่มความปลอดภัยในบทความนี้  คือการปิดเซอร์วิสที่ไม่ได้ใช้งานโดยไม่กระทบกับงานที่ลูกค้าใช้  ซึ่งนอกจากจะปิดช่องโหว่ที่อาจเกิดขึ้นแล้ว ยังได้ free memory เพิ่มคืนมาอีกด้วย ปิด remote services ตอนติดตั้ง Solaris วิธีการหนึ่งที่ช่วยปิดเซอร์วิสเก่าๆ สำหรับการ remote services ไม่ว่าจะเป็น telnet, rlogin, ftp  เหลือแค่ Secure Shell (SSH) สามารถทำได้ตั้งแต่ระหว่างการติดตั้ง Solaris ในหน้าจอที่เลือก &#8220;Enabling remote services&#8221; ให้เลือก [x] No สำหรับ &#8220;Remote services enabled&#8221; ปิดเซอร์วิส CDE-Login (X [...]]]></description>
			<content:encoded><![CDATA[<p>วันนี้ขอเขียนเกี่ยวกับ Solaris 10 ซะหน่อย ช่วงนี้ได้รับมอบหมายให้เพิ่มความปลอดภัย (secure) ให้กับเครื่อง Solaris  แต่มีข้อแม้ไม่อยากให้ลง JASS (Solaris Security Toolkit) ก็เลยลองทำดู และเรียบเรียงมาเป็นบทความให้ผู้สนใจทั่วไป</p>
<p>การเพิ่มความปลอดภัยในบทความนี้  คือการปิดเซอร์วิสที่ไม่ได้ใช้งานโดยไม่กระทบกับงานที่ลูกค้าใช้  ซึ่งนอกจากจะปิดช่องโหว่ที่อาจเกิดขึ้นแล้ว ยังได้ free memory เพิ่มคืนมาอีกด้วย<span id="more-681"></span></p>
<h4>ปิด remote services ตอนติดตั้ง Solaris</h4>
<p>วิธีการหนึ่งที่ช่วยปิดเซอร์วิสเก่าๆ สำหรับการ remote services ไม่ว่าจะเป็น telnet, rlogin, ftp  เหลือแค่ Secure Shell (SSH) สามารถทำได้ตั้งแต่ระหว่างการติดตั้ง Solaris ในหน้าจอที่เลือก &#8220;<strong>Enabling remote services</strong>&#8221; ให้เลือก <strong>[x] No</strong> สำหรับ &#8220;<strong>Remote services enabled</strong>&#8221;</p>
<p><img class="alignnone size-full wp-image-683" title="Solaris 10 Installation - Disable Remote Services" src="http://spalinux.com/wp-content/uploads/2009/05/00_install_solaris_10_disable_remote_services.png" alt="Solaris 10 Installation - Disable Remote Services" width="720" height="400" /></p>
<h4>ปิดเซอร์วิส CDE-Login (X Window)</h4>
<p>หากคุณไม่เคยเดินไปที่หน้าจอคอนโซลของเครื่อง login เข้า CDE หรือ W Window แล้ว  สามารถปิดเซอร์วิสนี้ไปได้เลย เหลือแค่เป็นคอนโซล แบบ text ธรรมดา ให้สามารถ login ได้</p>
<p>ใช้คำสั่ง svcs เพื่อตรวจสอบสถานะ cde-login</p>
<pre># <strong>svcs cde-login</strong>
 STATE          STIME    FMRI
 online         13:34:58 svc:/application/graphical-login/cde-login:default</pre>
<p>ตัวอย่างหน้าจอ cde-login</p>
<p><img class="alignnone size-full wp-image-684" title="Solaris 10 - CDE Login" src="http://spalinux.com/wp-content/uploads/2009/05/01_solaris_10_cde_login.png" alt="Solaris 10 - CDE Login" width="727" height="414" /></p>
<p>ใช้คำสั่ง svcadm disable เพื่อปิดเซอร์วิส cde-login</p>
<pre># <strong>svcadm disable cde-login</strong></pre>
<p>ตรวจสอบสถานะ cde-login หลังจากปิดเซอร์วิสแล้ว</p>
<pre># <strong>svcs cde-login</strong>
 STATE          STIME    FMRI
 disabled       13:36:59 svc:/application/graphical-login/cde-login:default</pre>
<p>ตัวอย่าง text console login หลังจากปิดเซอร์วิส cde-login</p>
<p><img class="alignnone size-full wp-image-685" title="After Disable CDE Login" src="http://spalinux.com/wp-content/uploads/2009/05/02_after_disable_cde.png" alt="After Disable CDE Login" width="720" height="400" /></p>
<h4></h4>
<h4>ปิดเซอร์วิส Sun Java Web Console</h4>
<p>Sun Java Web Console เป็นเซอร์วิสของ Solaris เพื่อสร้างเป็นจุดรวมของโปรแกรมประเภท system management ผ่านทาง web-based โดยผู้ใช้สามารถเรียกผ่าน https ได้</p>
<p><img class="alignnone size-full wp-image-688" title="Sun Java Web Console" src="http://spalinux.com/wp-content/uploads/2009/05/03_sun_java_web_console.png" alt="Sun Java Web Console" width="762" height="653" /></p>
<p>หากเราใช้แต่ command line เพื่อแก้ไขคอนฟิกเครื่อง เราสามารถปิดเซอร์วิสนี้ได้</p>
<p>ใช้คำสั่ง svcs เพื่อตรวจสอบสถานะ webconsole</p>
<pre># <strong>svcs webconsole</strong>
 STATE          STIME    FMRI
 online         14:01:06 svc:/system/webconsole:console</pre>
<p>ใช้คำสั่ง svcadm disable เพื่อปิดเซอร์วิส webconsole</p>
<pre># <strong>svcadm disable webconsole</strong></pre>
<p>ตรวจสอบสถานะ webconsole หลังจากปิดเซอร์วิสแล้ว</p>
<pre># <strong>svcs webconsole</strong>
 STATE          STIME    FMRI
 disabled       14:41:47 svc:/system/webconsole:console</pre>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li><a href="http://www.sun.com/software/security/jass/" target="_blank">Solaris Security Toolkit (JumpStart Architecture and Security Scripts &#8211; JASS &#8211; Toolkit)</a></li>
<li><a href="http://docs.sun.com/app/docs/doc/817-1985/ewpor?a=view" target="_blank">Working With the Sun Java Web Console</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2009/05/basic_secure_solaris_10/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>การกำหนด access list ใน Squid Proxy Server ตอนที่ 2</title>
		<link>http://spalinux.com/2009/01/define_access_list_in_squid_proxy_server_part_2</link>
		<comments>http://spalinux.com/2009/01/define_access_list_in_squid_proxy_server_part_2#comments</comments>
		<pubDate>Sat, 17 Jan 2009 06:12:49 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Proxy]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Squid]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=436</guid>
		<description><![CDATA[ในตอนที่สองนี้จะอธิบายดีฟอลต์คอนฟิก acl ที่ติดตั้งมากับ Fedora 10 โดยจะแยกเป็นส่วนๆ พร้อมทั้งแนะนำวิธีการแก้ไขคอนฟิกและการ reload เซอร์วิสหลังจากการแก้ไข ดีฟอลต์คอนฟิก acl ของ Squid เวอร์ชั่น squid-3.0.STABLE10 ที่ติดตั้งมากับ Fedora 10 จะแตกต่างจากเวอร์ชั่นก่อนๆ คือ อนุญาตเครื่องไคลเอนต์ที่มี ip address เป็น private  (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16) มีสิทธิใช้ proxy ซี่งแนะนำให้มีการแก้ไขก่อนนำไปใช้งานจริง อนุญาตให้ใช้งานและจัดการเกี่ยวกับ cache_object ได้จากในเครื่องที่ติดตั้ง (localhost) acl manager proto cache_object acl localhost src 127.0.0.1/32 acl to_localhost dst 127.0.0.0/8 http_access allow manager localhost http_access deny manager http_access [...]]]></description>
			<content:encoded><![CDATA[<p>ในตอนที่สองนี้จะอธิบายดีฟอลต์คอนฟิก acl ที่ติดตั้งมากับ Fedora 10 โดยจะแยกเป็นส่วนๆ พร้อมทั้งแนะนำวิธีการแก้ไขคอนฟิกและการ reload เซอร์วิสหลังจากการแก้ไข</p>
<p>ดีฟอลต์คอนฟิก acl ของ Squid เวอร์ชั่น squid-3.0.STABLE10 ที่ติดตั้งมากับ Fedora 10 จะแตกต่างจากเวอร์ชั่นก่อนๆ คือ อนุญาตเครื่องไคลเอนต์ที่มี ip address เป็น private  (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16) มีสิทธิใช้ proxy ซี่งแนะนำให้มีการแก้ไขก่อนนำไปใช้งานจริง</p>
<p><span id="more-436"></span></p>
<hr />
<h4>อนุญาตให้ใช้งานและจัดการเกี่ยวกับ cache_object ได้จากในเครื่องที่ติดตั้ง (localhost)</h4>
<pre>acl manager proto cache_object
acl localhost src 127.0.0.1/32
acl to_localhost dst 127.0.0.0/8

http_access allow manager localhost
http_access deny manager
http_access allow localhost
</pre>
<hr />
<h4>อนุญาตเครื่องไคลเอนต์ที่มี ip address เป็น private สามารถใช้งานได้</h4>
<pre>
acl localnet src 10.0.0.0/8 # RFC1918 possible internal network
acl localnet src 172.16.0.0/12  # RFC1918 possible internal network
acl localnet src 192.168.0.0/16 # RFC1918 possible internal network

http_access allow localnet
</pre>
<p>แนะนำให้ปิด (comment) ทั้งสี่บรรทัด ด้านบน แล้วค่อยกำหนด ip address ของไคลเอนต์ที่มีสิทธิใช้งาน proxy ได้อีกที</p>
<p>ปิดการอนุญาตเครื่องไคลเอนต์ที่มี ip address เป็น private</p>
<pre>
#acl localnet src 10.0.0.0/8 # RFC1918 possible internal network
#acl localnet src 172.16.0.0/12  # RFC1918 possible internal network
#acl localnet src 192.168.0.0/16 # RFC1918 possible internal network

#http_access allow localnet
</pre>
<hr />
<h4>ปฏิเสธการเชื่อมต่อโดยใช้พอร์ตของเว็บไซต์ ที่ไม่ใช่พอร์ต Safe_ports</h4>
<p>เบอร์พอร์ต Safe_ports มีดังนี้ 80, 21, 443, 70, 210, 280, 488, 597, 777, 1025-65535</p>
<pre>
acl Safe_ports port 80      # http
acl Safe_ports port 21      # ftp
acl Safe_ports port 443     # https
acl Safe_ports port 70      # gopher
acl Safe_ports port 210     # wais
acl Safe_ports port 1025-65535  # unregistered ports
acl Safe_ports port 280     # http-mgmt
acl Safe_ports port 488     # gss-http
acl Safe_ports port 591     # filemaker
acl Safe_ports port 777     # multiling http

http_access deny !Safe_ports
</pre>
<hr />
<h4>ปฏิเสธการเชื่อมต่อแบบ SSL ไปยังพอร์ตที่ไม่ใช่พอร์ตเบอร์ 443</h4>
<pre>
acl SSL_ports port 443
acl CONNECT method CONNECT

http_access deny CONNECT !SSL_ports
</pre>
<hr />
<h4>ปฏิเสธการใช้งานอื่นๆ ที่ไม่ match จาก acl ที่กำหนดไว้</h4>
<pre>http_access deny all</pre>
<hr />
<h4>วิธีการแก้ไขไฟล์คอนฟิก /etc/squid/squid.conf</h4>
<p>เพื่อสะดวกในการอ้างอิงภายหลัง การแก้ไขเพิ่มเติม acl ทั้งในส่วนกำหนดชื่อ aclname และการอนุญาตหรือปฏิเสธ ในไฟล์ /etc/squid/squid.conf ให้แก้ไขใต้บรรทัด ที่มีคำว่า</p>
<pre>
# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS</pre>
<p>หลังจากแก้ไขไฟล์คอนฟิกของ squid ต้องใช้คำสั่ง service reload เซอร์วิส เพื่อให้คอนฟิกใหม่มีผล</p>
<pre>[root@proxy ~]# <strong>service squid reload</strong></pre>
<p>หากมีข้อผิดพลาดในคอนฟิก จะมี error ฟ้องขึ้นมา ต้องแก้ไขให้ถูกต้อง คอนฟิกใหม่ถึงจะมีผล</p>
<p>ตัวอย่างการกำหนด ip address ผิดในไฟล์คอนฟิก</p>
<pre>
[root@proxy ~]# <strong>service squid reload</strong>
2009/01/17 12:58:36| aclParseIpData: Bad host/IP: '192.168.1.02-'
FATAL: Bungled squid.conf line 643: acl acl_client1 src 192.168.1.02-
Squid Cache (Version 3.0.STABLE10): Terminated abnormally.
CPU Usage: 0.005 seconds = 0.001 user + 0.004 sys
Maximum Resident Size: 0 KB
Page faults with physical i/o: 0
</pre>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li><a href="http://spalinux.com/2009/01/define_access_list_in_squid_proxy_server_part_1">การกำหนด access list ใน Squid Proxy Server ตอนที่ 1</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2009/01/define_access_list_in_squid_proxy_server_part_2/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

