Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts
Cách build php module cho Apache

Có nhiều cách build php để chạy với Apache, cách build php từ source thành một module của apache là cách đơn giản nhất, mình mới thử làm, các bạn xem và thảo luận nhé:
1.Download bản mới nhất về, giải nén ra:


Code:

wget http://www.php.net/get/php-5.3.7.tar.gz/from/hk.php.net/mirror
tar xvzf php-5.3.7.tar.gz


2. Cài đặt và cấu hình
-Tiến hành

Code:

cd ../php-5.3.7
./configure --with-apxs2=/usr/local/apache2/bin/apxs
make
make install


-Tiến hành khởi động lại apache

Code:

/etc/init.d/httpd restart


-Tạo file php.ini

Code:

cp php.ini-development /usr/local/lib/php.ini


3.Kiểm tra cấu hình httpd.conf load php module
Tìm dòng:

Code:

LoadModule php5_module modules/libphp5.so


4.Cấu hình Apache sử lí file PHP:
-

Code:

<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>


-Nếu bạn muốn dùng nhiều loại file với mở rông: .php, .php2, .php3, .php4, .php5, .php6, and .phtml

Code:

<FilesMatch "\.ph(p[2-6]?|tml)$">
SetHandler application/x-httpd-php
</FilesMatch>


5. Khởi động lại apache, tạo file phpinfo kiểm tra và hoàn tất.

View more: http://www.seaoffire.net/fcgi-faq.html#III-A

Source: quntrilinux.com

Install Proxmox with USB

This is tutorial boot proxmox with USB. You must burn file *.iso. And then download a tool that will convert your usb stick into a bootable one (for example, unetbootin or usb universal installer).

Run program and choose: "Try Unlisted Linux ISO” --> create.

And then copy file *.iso (of proxmox) to usb.

Boot USB and type : debug (for debug)

When the boot process is completed, you will see a message similar to “no cdrom found – unable to continue (type exit or Ctrl-D to reboot)

From the console, I’ll simply type fdisk -l.

mount /dev/sdb1 /mnt (note : the /dev/sdb1 represent my stick on my system — Please change this value to reflect your settings)

mount -o loop -t iso9660 /mnt/proxmox_1-7.iso /mnt (again change accordingly based the name of your iso file… )

chroot /mnt  sbin/unconfigured.sh


If everything works as expected, you should see the ProxMox VE installer (the GUI basically) and you can go through the wizard to perform your installation.


Source: http://c-nergy.be/blog/?p=897

How to change the primary monitor in Ubuntu or other Linux distributions

Using dual or multiple monitors in Linux is relatively straightforward as most monitors are automatically detected on the major distributions. However, Gnome does not give an option for specifying which monitor is the primary - that is to say the monitor which holds the panels by default and is considered the 'default' display. Fortunately, the xrandr utility can easily switch which monitor is the primary. Copy and paste the following script into a text file called monitor-switcher.sh.

Cấu hình Dynamic DNS client trên Linux

Cấu hình Dynamic DNS client

Những người truy cập Internet bằng cách quay số điện thoại (dial-up) hay ADSL thường không được ISP cấp địa chỉ IP cố định (tại sao? xem phần tham khảo). Mỗi lần truy cập, hay mỗi lần truy cập lại do kết nối bị ngắt, người dùng thường được cấp một địa chỉ IP khác với địa chỉ IP của lần kết nối trước.

Trong những trường hợp này, thay đổi thông tin DNS theo cách bình thường (sửa zone file bằng tay!) tỏ ra bất tiện và chậm chạp. Thay vào đó, người ta cập nhật DNS bằng Dynamic DNS, cách này có những đặc điểm:

1. cập nhật tự động mỗi khi có thay đổi
2. thời hạn có nghĩa của DNS (xác định bằng “negative cache”) bé, do đó những thay đổi về DNS sẽ được cập nhật nhanh chóng

Có nhiều nơi cung cấp dịch vụ dynamic DNS (free, hoặc phải mất một khoản tiền nào đó), và có nhiều chương trình dynamic dns client. Bạn có thể chọn từ danh sách sau đây (xem phần tham khảo ở cuối bài).

Bài viết này giới thiệu cách cấu hình ddclient, một Dynamic DNS client cho máy Linux. ddlient được viết bằng Perl, có thể chạy ở chế độ daemon, thích hợp với nhiều loại router, và có thể dùng với những account của các dịch vụ DynDNS.org, ZoneEdit.

Bắt đầu viết: tháng 5 năm 2003.
Thay đổi lần cuối vào lúc: Sun Feb 1 12:47:44 JST 2004.

Cài đặt và cấu hình ddclient

Phần 1: Đăng kí một account ở DynDNS.org, hoặc ở ZoneEdit, nhớ kiểm tra userID và password trước khi sang phần 2.

Phần 2: Cài đặt ddclient

Download, giải nén, và đọc file README. Nếu đọc kĩ README, bạn có thể tự làm được mà không cần xem tiếp những điều ghi dưới đây!

// download ddclient v3.6.3
$ wget http://s90389134.onlinehome.us/ddclient/ddclient.tar.gz
// update: ddclient đã được chuyển thành một project ở sf.net
// http://sourceforge.net/projects/ddclient

// giải nén
$ tar zxvf ddclient.tar.gz
// hoặc tar jxvf ddclient.tar.bz2

// đọc file ddclient-3.6.3/README!

Copy những file cần thiết vào chỗ thích hợp

// chương trình chính
# cp ddclient-3.6.3/ddclient /usr/sbin

// file cấu hình
# cp sample-etc_ddclient.conf /etc/ddclient.conf

// chuẩn bị script khởi động
# cp sample-etc_rc.d_init.d_ddclient /etc/init.d/ddclient

Cấu hình file /etc/ddclient.conf

daemon=300 # kiểm tra IP, 5 phút (300 sec) 1 lần
syslog=yes # ghi thay đổi IP vào syslog
mail=root # thông báo thay đổi cho root
mail-failure=root # thông báo lỗi cho root
pid=/var/run/ddclient.pid # thông tin PID

### cho người dùng dyndns.org
login=userID # userID đã đăng kí với dyndns.org
password=mật khẩu DynDNS.org
server=members.dyndns.org, \
protocol=dyndns2 \
name1.dyndns.org,name2.homelinux.net

### cho người dùng ZoneEdit
server=www.zoneedit.com, \
protocol=zoneedit1, \
login=userID, \ # userID đã đăng kí với ZoneEdit
password=mật khẩu ZoneEdit \
domain1.name,domain2.name

### 2 kiểu cấu hình phổ biến
### kiểu 1
### nếu interface ppp0 được cấp global dynamic IP address
### ví dụ: trường hợp ADSL modem hoạt động như một bridge
use=if, if=ppp0 # kiểm tra IP ở interface ppp0

### kiểu 2
### nếu máy Linux chỉ có private IP address
### ví dụ: trường hợp ADSL modem hoạt động như một router (và NAT)
use=web, web=members.orgdns.org/nic/ip
### update: members.orgdns.org có vẻ không còn hoạt động
### dùng url sau đây để kiểm tra IP
### use=web, web=checkip.dyndns.org, web-skip=’Current IP Address:’

Mọi chuẩn bị như vậy là xong, chỉ còn việc khởi động ddclient

### sửa file /etc/init.d/ddclient, chỉ cho phép
### khởi động ở level 3, xong gõ lệnh
/sbin/chkconfig –add ddclient

### không biết cách sửa file /etc/init.d/ddclient thì làm
chkconfig –level 012456 ddclient off
chkconfig –level 3 ddclient on
### như vậy, mỗi lần bật máy, ddclient daemon sẽ được khởi động

### lần đầu tiên, cần khởi động ddclient bằng cách
/etc/init.d/ddclient start

Tham khảo, thông tin thêm

1. Từ lúc IP thay đổi đến lúc DNS được cập nhật, mất bao nhiêu thời gian?
* thời gian cập nhật tối đa, tính từ lúc IP thay đổi
= chu kỳ kiểm tra IP của ddclient daemon + thời gian cache thông tin DNS (negative cache)
= 300 + 60 (của DynDNS.org) = 360 sec (6 phút)
Chú ý: ở đây bỏ qua thời gian xử lý ở client, DNS server (cỡ milisec), thời gian gian truyền dữ liệu trên Internet (cỡ vài trăm milisec).
2. Tại sao không được cấp IP cố định (static global IP address)?
* còn nữa
3. Những nơi cung cấp dịch vụ Dynamic DNS và điều kiện sử dụng
* Danh sách của technopagan
4. Một vài dynamic dns client
* xem danh sách ở DynDNS.org

(Lấy từ: http://james.dyndns.ws/)

Cài đặt Zabbix trên CentOS
Đồng bộ dữ liệu giữa các Node trong mô hình Web Cluster

I – Giới thiệu:

Ở bài trước, mình có trình bày Cấu hình Web Cluster giúp tăng tính sẵn sàng cho hệ thống Web Server của chúng ta. Tuy nhiên, nếu một Node trong hệ thống Cluster “chết”, sau một thời gian sau Node đó “sống” trở lại thì dữ liệu trên Node không còn nhất quán với các Node còn lại nữa!. Trong bài này, mình sẽ tiếp tục trình bày về đồng bộ dữ liệu giữa các Node trong mô hình Web Cluster.

cluster_sync_0


Cấu hình Web Cluster

I – Mô hình & Yêu cầu:

Mô hình:

web_cluster_synchronization_0




Một số câu lệnh kiểm tra server khi bị tấn công DDoS

Một số câu lệnh kiểm tra server khi bị tấn công DDoS

- Kiểm tra số connection trên port 80:


Code:

netstat -n | grep :80 |wc -l


- Kiểm tra số lượng connection đang ở trạng thái SYN_RECV:

Code:

netstat -n | grep :80 | grep SYN_RECV|wc -l


- Hiển thị tất cả các IP đang kết nối và số lượng kết nối từ mỗi IP:

Code:

netstat -an|grep :80 |awk '{print $5}'|cut -d":" -f1|sort|uniq -c|sort -rn


Nếu muốn kiểm tra IP nào mở nhiều SYN thì thêm vào:

Code:

netstat -an|grep :80|grep SYN |awk '{print $5}'|cut -d":" -f1|sort|uniq -c|sort -rn


- Đối với server có nhiều IP, để kiểm tra IP nào đang bị tấn công:

Code:

netstat -plan  | grep  :80 | awk '{print $4}'| cut -d: -f1 |sort |uniq -c


Bài viết trên sẽ có vài trường hợp ra kết quả không đúng nếu như sử dụng kernel mới , IP có dạng '::ffff:192.168.1.1:80' . Để tổng quát hơn các bạn nên dùng như sau cho mọi trường hợp :

- Hiển thị tất cả các IP đang kết nối và số lượng kết nối từ mỗi IP:

Code:

[root@localhost~]# netstat -an | grep ':80' | awk '{print $5}' | sed s/'::ffff:'// | cut -d":" -f1 | sort | uniq -c


Đồng thời mình bổ xung thêm :
- Hiển thị số lượng kết nối mỗi loại (kiểm tra xem có phải bị SYN_FLOOD hay DDoS hay ko) :

Code:

root@localhost [~]# netstat -an | grep :80 | awk '{print $6}' | sort | uniq -c
61 ESTABLISHED
13 FIN_WAIT1
17 FIN_WAIT2
1 LISTEN
25 SYN_RECV
298 TIME_WAIT


Trong trường hợp đang bị tấn công , cần phải quan sát các tham số trên một các real time => dùng lệnh 'watch' :

- Hiển thị tất cả các IP đang kết nối và số lượng kết nối từ mỗi IP:

Code:

[root@localhost~]#watch  "netstat -an | grep ':80' | awk '{print \$5}' | sed s/'::ffff:'// | cut -d\":\" -f1 | sort | uniq -c"


- Hiển thị số lượng kết nối mỗi loại :

Code:

root@localhost [~]# watch "netstat -an | grep :80 | awk '{print \$6}' | sort | uniq -c"

How To Reset Linux Firewall Automatically While Testing ConfigurationWith Remote Server Over SSH Session

Q. I'd like to tell my Linux iptables firewall to flush out the current configuration every 5 minutes. This will help when I'm testing a new rules and configuration options. Some time I find myself locked out of my own remote server. How do I reset Linux firewall automatically without issuing hard reboot?

A. You can easily flush out current configuration using iptables command and shell script combo. There is no built in option for this kind of settings. So you need to write a small shell script and call it from crontab file.

Create a firewall reset shell script


Create a /root/reset.fw script:
#!/bin/bash
# reset.fw - Reset firewall
# set x to 0 - No reset
# set x to 1 - Reset firewall
# ---------------------------------------------------------------------------------------------------------------
# Added support for IPV6 Firewall
# ---------------------------------------------------------------------------------------------------------------
# Written by Vivek Gite <vivek@nixcraft.com>
# ---------------------------------------------------------------------------------------------------------------
# You can copy / paste / redistribute this script under GPL version 2.0 or above
# =============================================================
x=1

# set to true if it is CentOS / RHEL / Fedora box
RHEL=false

### no need to edit below  ###
IPT=/sbin/iptables
IPT6=/sbin/ip6tables

if [ "$x" == "1" ];
then
if [ "$RHEL" == "true" ];
then
# reset firewall using redhat script
/etc/init.d/iptables stop
/etc/init.d/ip6tables stop
else
# for all other Linux distro use following rules to reset firewall
### reset ipv4 iptales ###
$IPT -F
$IPT -X
$IPT -Z
for table in $(</proc/net/ip_tables_names)
do
$IPT -t $table -F
$IPT -t $table -X
$IPT -t $table -Z
done
$IPT -P INPUT ACCEPT
$IPT -P OUTPUT ACCEPT
$IPT -P FORWARD ACCEPT
### reset ipv6 iptales ###
$IPT6 -F
$IPT6 -X
$IPT6 -Z
for table in $(</proc/net/ip6_tables_names)
do
$IPT6 -t $table -F
$IPT6 -t $table -X
$IPT6 -t $table -Z
done
$IPT6 -P INPUT ACCEPT
$IPT6 -P OUTPUT ACCEPT
$IPT6 -P FORWARD ACCEPT
fi
else
:
fi

Set permissions:
# chmod +x /root/reset.fw
Create cronjon to reset current configuration every 5 minutes, enter
# crontab -e
OR
# vi /etc/crontab
Append following settings:
*/5 * * * * root /root/reset.fw >/dev/null 2>&1
Please remember to set x to 0 once a working configuration has been created for your Linux system.

Test Iptables Script Remotely


How do I test iptables based script remotely over ssh session? How do I avoid lock outs?

iptables do not have pf like testing option. However, you can use a shell script and cron combo or just use the following syntax:
# /sbin/service iptables restart; sleep 20; /sbin/service iptables stop &
This way you can recover from bad syntax error. If you have your own script:
# /path/to/your.script.sh; sleep 20; /sbin/service iptables stop &
Above will allow you to test changes for a while and then turn off firewall completely. You will be able to login again using ssh after 20 seconds if locked out.

Source: http://www.cyberciti.biz/faq/linux-iptables-firewall-flushout-configuration-every-5minutes/

UBUNTU check free memory and free mem empty cache

check memory usage:

cat /proc/meminfo

or

free

free command displays amount of total, free and used physical memory (RAM) in the system, as well as shoing information on shared memory, buffers, cached memory and swap space used by the Linux kernel.

Syntax of free

free -[options]

Example usage of free

free -m

The command will display information about physical memory in MB.

free -m -s 5

The command will activate continuous polling delay at 5 seconds apart, and then display memory status in megabytes on terminal. Any floating point number for delay can be specified.

free -t -m

Same with “free -m”, but -t switch will display a line containing the totals of physical memory and swap space.

vmstat

vmstat reports report virtual memory statistics, which has information about processes, swap, free, buffer and cache memory, paging space, disk IO activity, traps, interrupts, context switches and CPU activity. With vmstat command, administrators can has instantaneous reports on memory usage.

Syntax of vmstat

vmstat -[options] [delay count]

Example usage of vmstat

vmstat

The command will display report based on averages since last reboot.

vmstat 5

The command will pool average system resources usage level for a sampling period of 5 seconds at interval of 5 seconds, except the first result that is averages since the last reboot.

empty / free up memory caches

To free pagecache:
echo 1 > /proc/sys/vm/drop_caches

To free dentries and inodes:

echo 2 > /proc/sys/vm/drop_caches

To free pagecache, dentries and inodes:

echo 3 > /proc/sys/vm/drop_caches

As this is a non-destructive operation and dirty objects are not freeable, the user should run “sync” first!

This was originally found @ http://www.linuxinsight.com/proc_sys_vm_drop_caches.html

Source: http://stuffthatspins.com/2011/01/20/ubuntu-check-free-memory-and-free-mem-empty-cache/

Một số lệnh Linux cơ bản

Khi "kết thân" với Linux, nếu không nắm được một số câu lệnh cần thiết thì công việc quản trị của bạn sẽ gặp không ít khó khăn. Dưới đây là một số lệnh Linux cơ bản giúp cho việc quản trị của bạn dễ dàng hơn rất nhiều.

1. Hiển thị tiến trình trong hệ thống Linux

Một trong những công việc cần thiết khi quản trị hệ thống Linux đó là kiểm soát các tiến trình hiện đang chạy. Khi đã biết được những tiến trình nào đang chạy bạn có thể tắt những tiến trình gây giảm tốc độ của hệ thống. Ngoài ra, thông tin về những tiến trình hệ thống cho chúng ta biết nên tắt nhưng tiến trình làm cho hệ thống vận hành không ổn định. Do đó việc biết được những tiến trình nào đang chạy trên hệ thống rất quan trọng. Linux hỗ trợ nhiều phương pháp kiểm tra tiến trình, một trong số đó là sử dụng lệnh ps. Khi sử dụng lệnh này mọi thông tin về những tiến trình đang chạy sẽ được hiển thị. Bạn chỉ cần nhập cú pháp lệnh sau vào cửa sổ terminal:

# ps aux | less



Hình 1: Thông tin tiến trình đang chạy trong hệ thống.

Ngoài ra lệnh này có thể sử dụng kết hợp với một số tham số khác như:
# ps –A: Kiểm tra mọi tiến trình trong hệ thống.
# ps -U root -u root –N: Kiểm tra mọi tiến trình ngoại trừ những tiến trình hệ thống.
# ps -u username: Kiểm tra những tiến trình được thực hiện bởi một người dùng nhất định.

Hoặc bạn có thể sử dụng lệnh # top để xem những tiến trình đang chạy trên hệ thống trong thời gian thực.

2. Kiểm tra thông tin Socket và thông tin mạng TCP/UDP

Sau khi cấu hình những dịch vụ mạng của hệ thống Linux, bạn cần phải giữ lại tab của các cổng đang thực sự nhận tín hiệu trên giao diện mạng của hệ thống. Điều này rất quan trọng vì hệ thống có thể bị xâm nhập qua các cổng mở. Có một số công cụ quản lý Linux thông báo cho bạn biết thông tin của những cổng mởvà truy cập vào những cổng đang mở trên mạng. Một trong những phương pháp đơn giản và tin cậy nhất đó là sử dụng lệnh ss để kiểm tra thông tin Socket, ngoài ra lệnh này còn có thể hiển thị nhiều thông tin TCP và thông tin trạng thái hơn các công cụ khác. Lệnh ss này cung cấp thông tin về:
  • Mọi Socket TCP.
  • Mọi Socket UDP.
  • Mọi kết nối ssh/ftp/http/https.
  • Mọi tiến trình cục bộ được kết nối tới máy chủ X.
  • Mọi Socket TCP trong trạng thái FIN-WAIT-1.

Dưới đây là một số lệnh ss:
# ss –s: Hiển thị tổng số Socket.



Hình 2: Thông tin kết xuất khi chạy lệnh # ss –s.

# ss -1: Hiển thị mọi cổng mở.



Hình 3: Thông tin kết xuất khi chạy lệnh # ss -1.

# ss –pl: Kiểm tra tên tiến trình sử dụng Socket mở sử dụng lệnh sau:

# ss -lp | grep: Kiểm tra người dùng đang làm việc với Socket mở.

# ss -t –a: Hiển thị mọi Socket TCP.

# ss -u –a: Hiển thị mọi Socket UDP.

3. Theo dõi Average CPU Load và Disk Activity

Nếu là một quản trị viên hệ thống Linux, bạn cần phải biết phương pháp duy trì một sự cân bằng hợp lý trong quá trình tải đầu vào và đầu ra giữa các ổ đĩa vật lý. Bạn có thể thay đổi cấu hình hệ thống để thực hiện tác vụ này. Tuy nhiên có một phương pháp đơn giản hơn rất nhiều đó là sử dụng lệnh isostat để quản lý hệ thống thiết bị tải đầu vào và đầu ra trong Linux bằng cách theo dõi thời gian hoạt động và tốc độ truyền trung bình của những thiết bị này. Lệnh này sẽ thông báo thông tin của CPU (Central Processing Unit), thông tin đầu vào và đầu ra cho những thiết bị, phân vùng và hệ thống file mạng (NFS).
Khi chạy lệnh isostat thông tin kết xuất có dạng:


Hình 4: Thông tin hiển thị khi chạy lệnh isostat.

Để lấy thông tin thư mục NFS bạn hãy sử dụng lệnh sau:
# iostat –n

4. Kiểm tra Memory Map của các tiến trình trong Linux

Khi làm việc trong hệ thống Linux có thể bạn cần kiểm tra dung lượng bộ nhớ sử dụng trong hệ thống. Linux tích hợp nhiều lệnh cho phép kiểm tra dung lượng bộ nhớ chiếm dụng. Trong đó có một lệnh đơn giản giúp hiển thị thông tin tổng dung lượng đã chiếm dụng và chưa chiếm dụng của bộ nhớ vật lý và tổng dung lượng bộ nhớ đó là lệnh free.

Sau khi chạy lệnh này bạn sẽ thấy tổng dung lượng đã chiếm dụng và chưa chiếm dụng của bộ nhớ vật lý và tổng dung lượng bộ nhớ trong hệ thống. Ngoài ra nó còn hiển thị thông tin bộ nhớ đệm mà các nhân sử dụng.


Hình 5: Thông tin hiển thị sau khi chạy lệnh free


5. Kiểm tra thời gian vận hành của hệ thống


Bạn có muốn biết máy chủ đã vận hành bao lâu? Nếu muốn bạn chỉ cần sử dụng lênh uptime để kiểm tra thời gian mà hệ thống đã vận hành. Lệnh đơn giản này không chỉ cho bạn biết thời gian hệ thống vận hành mà còn cho biết lượng người dùng đã đăng nhập vào hệ thống trong một khoảng thời gian trước đó.


Hình 6: Kết quả lệnh uptime.

6. Kiểm tra người dùng đăng nhập

Ngoài những công cụ quản lý Linux, bạn có thể sử dụng một lệnh để kiểm tra những người dùng nào đã thực hiên đăng nhập vào hệ thống và những gì họ đã thực hiện. Lệnh này sẽ hiển thị thời gian hiện tại, thời gian hệ thống đã vận hành, lượng người dùng đã đăng nhập.

Ngoài ra lệnh này cũng hiển thị lượng tải trung bình trong mỗi 1, 5 và 15 phút. Lệnh này rất hữu dụng với những Admin hệ thống muốn sử dụng thông tin tải trung bình để hoạch định dung lượng.

Để kiểm tra ai đã đăng nhập vào hệ thống và những tác vụ họ đã thực hiện bạn chỉ cần chạy lệnh sau:
# w username



Hình 7: Thông tin hiển thị sau khi chạy lệnh # w username.

7. Kiểm soát hành vi hệ thống, phần cứng và thông tin hệ thống trong Linux

Với nhiều người dùng Linux, kiểm soát hệ thống là một tác vụ phức tạp. Hầu hết các bản phân phối Linux tích hợp khá nhiều công cụ kiểm soát. Những công cụ kiểm soát này cung cấp các phương pháp có thể được áp dụng để kiểm tra thông tin hành vi hệ thống. Việc kiểm soát hệ thống cho phép người dùng theo dõi nguyên nhân khả năng thực thi của hệ thống bị cản trở. Một trong những tác vụ cần thiết của quá trình kiểm soát hệ thống là tra cứu thông tin về hành vi hệ thống, phần cứng và thông tin bộ nhớ. Có một lệnh đơn giản giúp hiển thị thông tin về tiến trình, bộ nhớ, trang ghi, nhóm IO, lỗi và hành vi CPU đó là lệnh vmstat.

Bạn chỉ cần nhập lệnh sau vào cửa sổ terminal:
# vmstat 3


Hình 8: Thông tin kết xuất của lệnh # vmstat 3.

Ngoài ra bạn có thể sử dụng lệnh # vmstat –m để kiểm tra thông tin bộ nhớ, và lệnh # vmstat –a để hiển thị thông tin trang nhớ đang hoạt động và không hoạt động.


Hình 9: Thông tin hiển thị sau khi chạy lệnh # vmstat –a.

8. Kiểm tra thông tin phần cứng của hệ thống Linux

Với một số người dùng Linux thì việc kiểm tra thông tin phần cứng thật không dễ dàng. Linux là một hệ thống phức tạp nhưng nó lại tích hợp một số công cụ giúp lấy thông tin chi tiết của phần cứng, chẳng hạn chúng ta có thể sử dụng một lệnh khá đơn giản để kiểm tra thông tin đĩa cứng trên hệ thống đó là lệnh hdparm. Lệnh này cung cấp một giao diện dòng lệnh để thực hiện quản lý nhiều loại đĩa cứng được hệ thống phụ điều khiển thiết bị ATA/IDE của Linux hỗ trợ. Nó cung cấp một lệnh giúp hiển thị thông tin xác minh như dung lượng, thông tin chi tiết, … trực tiếp từ ổ đĩa. Thông tin này được lưu dưới một định dạng mở rộng mới. Bạn chỉ cần đăng nhập dưới quyền root user và sử dụng lệnh sau:
# hdparm -I /dev/sda

Hoặc dùng lệnh:
$ sudo hdparm -I /dev/sda

Khi đó thông tin về đĩa cứng của hệ thống sẽ lập tức hiển thị.


Hình 10: Thông tin chi tiết của đĩa cứng .

Nhận dạng thiết bị trong Linux bằng Window driver

Như chúng ta đã biết, Linux có 1 nền tảng hỗ trợ phần cứng khá đa dạng, nhưng bạn sẽ làm gì nếu hệ điều hành Linux đang sử dụng không nhận diện chính xác một thiết bị nào đó. Trong bài viết dưới đây, chúng tôi sẽ trình bày một số bước cơ bản để khắc phục vấn đề này bằng Windows driver và ndiswrapper.

Cụ thể chúng tôi sẽ tiến hành thử nghiệm với thiết bị card Wireless. Việc sử dụng driver của Windows trong nền tảng Linux có thể sẽ giúp card Wireless có tốc độ truyền tải dữ liệu nhanh hơn và hỗ trợ khả năng mã hóa tốt hơn. Nhưng nếu thiết bị hoạt động bình thường, chúng tôi khuyến cáo các bạn không nên tiếp tục vì sẽ gây ra sự xung đột với driver sẵn có của Linux.

Việc trước tiên cần làm là tìm ra thông tin, nguồn gốc chính xác của thiết bị. Ví dụ như ở trong bài thử nghiệm này là mẫu AE1000 của Cisco:



Sau đó, truy cập vào trang chủ và tải driver dành cho Windows. Tốt nhất là các bạn nên tải phiên bản driver dành cho Windows XP 32-bit dưới dạng .zip thay vì .exe. Nếu không, hãy chọn bản dành cho hệ điều hành Windows mới nhất. Sau đó, giải nén file bằng chương trình thích hợp:



Sau đó, tiến hành cài đặt Ndiswrapper qua Software Center của Ubuntu. Lưu ý rằng công cụ này đã được cài đặt sẵn trong Linux Mint:



Tiếp đó, các bạn mở Windows Wireless Drivers từ System -> Administration:



Chọn tiếp Install New Driver và trỏ tới thư mục vừa giải nén driver ở bước trên:



Đôi khi file .inf nằm trong thư mục con bên trong, cho nên bạn cần tìm kỹ:



Sau khi chọn được file .inf thích hợp, nhấn Install. Quá trình này diễn ra trong khoảng 1 – 2 phút:



Khi kết thúc quá trình này, trong cửa sổ chính của chương trình sẽ hiển thị các driver phù hợp đi kèm với file .inf bên phải. Nếu bạn chọn nhầm driver trong lần đầu tiên, các bạn hãy thử lại với file .inf khác. Trong trường hợp không có file .inf nào hoạt động, thì bạn hãy thử với các phiên bản Windows khác, ví dụ như Windows, Vista, 7:



Khi hoàn tất, chúng ta chỉ việc mở mục Ubuntu Network Connections và tiến hành kết nối như bình thường:



Chúc các bạn thành công!

Tìm hiểu về /dev/null

Trong quá trình sử dụng linux hay xem các bài hướng dẫn bảo mật chắc các bạn đã từng nghe nhiều đến một file đặt biệt trong hệ thống các file của linux là file /dev/null. Hôm nay tớ xin viết một bài giới thiệu về file này để các bạn cùng hiểu thêm về hệ thống file của linux, ngoài ra có thể áp dụng nó trong việc bảo mật.

1. Trong linux mọi thứ là file.

Điều căn bản này rất quan trọng nên tớ xin nhấn mạnh lại một lần nữa, hệ điều hành linux xem mọi thứ đều là "file" và theo định nghĩa thì file là" a block of arbitrary information, or resource for storing information".

Vì vậy dễ dàng nhận thấy đối với linux thì folder cũng là file. Nhưng để làm việc hiệu quả thì linux cũng cần phải chia ra làm nhiều loại file khác nhau phục vụ cho công việc, thông thường thì có 7 loại chính sau đây.

Code:

d = directory
l = symbolic link
s = socket
p = named pipe
- = regular file
c = character (unbuffered) device file special
b = block (buffered) device file special

Các bạn thử gõ lệnh sau đây xem
Code:

ls -al /dev/null

Kết quả cho ra sẽ là
Code:

crw-rw-rw- 1 root root 1, 3 2011-04-26 13:00 /dev/null

Vậy nên có thể kết luận /dev/null là loại "character (unbuffered) device file special" (nội dung bài này không phải là phân tích cấu trúc các file linux nên phần này tớ bỏ qua không giải thích nhé).

2. Đặt điểm của /dev/null

/dev/null (còn gọi là "the null device") là một file có đặt điểm là vứt bỏ (discards) mọi dữ liệu mà người dùng ghi vào trong nó (thường thông qua các lệnh chuyển hướng của shell hay các lệnh mv, cp,...), nhưng nó vẫn báo là hoàn thành quá trình ghi vào chớ không sinh ra lỗi. Và vì file này không lưu gì vào trong cả nên dĩ nhiên là cũng không xuất ra bất cứ cái gì.

Người ta xem như nó là một "lỗ đen" trong máy tính, có tác dụng thu nhận mọi thứ và không giới hạn, nhưng chả trả lại cái gì cả

3. Ứng dụng của file /dev/null

Dựa vào trong những đặt điểm trên của file /dev/null, nó được ứng dụng rộng rãi kể cả trong bảo mật (thậm chí mục tiêu bảo mật là chính), một vài ứng dụng của nó trong bảo mật là:

- Các gói tin nào không phù hợp thường được firewall chuyển vào trong /dev/null
- Các email server cũng thường được config để chuyển các email spam vào trong /dev/null giúp không bị đầy hdd
- Trong các chương trình bắt buộc phải có đầu ra dữ liệu, nhưng vì bảo mật bạn không muốn nó xuất hiện các thông tin đầu ra ví dụ .bash_history của root thì cũng có thể dùng /dev/null
- Ngoài ra các bạn còn có thể tạo các file rỗng bằng cách lấy dữ liệu trong /dev/null ra.
- ... và còn nhiều thứ nữa.

WordPress permalink on CentOS 5 tutorial

The installation of WordPress is simple and straightforward. Really. So I’m not going to detail the installation process, which is well documented here. However, the permalink feature does not work out of the box on a standard CentOs 5 distribution. Some changes have to be made in the apache configuration files to enable mod_rewrite in your WordPress directory.

Let’s say you installed WordPress in the root of your website. By default on your CentOs’s apache, the document root of your website is located in /var/www/html.

    1. create an empty a .htaccess file in this directory.
    2. WordPress should be able to read/write this file when updating your settings in the admin pages, so make sure the user running apache has the right to write this file. If not, chmod/chown it. Usually this should do the trick:
      chown apache:apache /var/www/html/.htaccess

    3. now edit the /etc/httpd/conf/httpd.conf file. Search the following:

<Directory "/var/www/html">


# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
#   Options FileInfo AuthConfig Limit
#
AllowOverride None

  1. Change this line to:
    AllowOverride All

    This allows apache to read and interpret the .htaccess located in you document root.
  2. Restart Apache
  3. Now you can change your permalink settings in the admin pages of WordPress, which will modify the .htaccess file created above.Check the rights of the .htaccess file, maybe apache can write it but not read it.
  4. If so, try :chmod a+r /var/www/html/.htaccess

2. Config permalink for VirtualHost:
<VirtualHost *:80>
ServerAdmin webmaster@host.foo.com
DocumentRoot /www/docs/host.foo.com
ServerName host.foo.com
ErrorLog logs/host.foo.com-error_log
CustomLog logs/host.foo.com-access_log
<Directory /www/docs/host.foo.com/>
Options FollowSymLinks
</Directory>
</VirtualHost>

25 BEST SSH COMMANDS / TRICKS

OpenSSH is a FREE version of the SSH connectivity tools that technical users of the Internet rely on. Users of telnet, rlogin, and ftp may not realize that their password is transmitted across the Internet unencrypted, but it is. OpenSSH encrypts all traffic (including passwords) to effectively eliminate eavesdropping, connection hijacking, and other attacks. Additionally, OpenSSH provides secure tunneling capabilities and several authentication methods, and supports all SSH protocol versions.

SSH is an awesome powerful tool, there are unlimited possibility when it comes to SSH, heres the top Voted SSH commands

1) COPY SSH KEYS TO USER@HOST TO ENABLE PASSWORD-LESS SSH LOGINS.

ssh-copy-id user@host

To generate the keys use the command ssh-keygen

2) START A TUNNEL FROM SOME MACHINE’S PORT 80 TO YOUR LOCAL POST 2001
ssh -N -L2001:localhost:80 somemachine

Now you can acces the website by going to http://localhost:2001/

3) OUTPUT YOUR MICROPHONE TO A REMOTE COMPUTER’S SPEAKER
dd if=/dev/dsp | ssh -c arcfour -C username@host dd of=/dev/dsp

This will output the sound from your microphone port to the ssh target computer’s speaker port. The sound quality is very bad, so you will hear a lot of hissing.

4) COMPARE A REMOTE FILE WITH A LOCAL FILE
ssh user@host cat /path/to/remotefile | diff /path/to/localfile -

Useful for checking if there are differences between local and remote files.
5) MOUNT FOLDER/FILESYSTEM THROUGH SSH

sshfs name@server:/path/to/folder /path/to/mount/point

Install SSHFS from http://fuse.sourceforge.net/sshfs.html
Will allow you to mount a folder security over a network.

6) SSH CONNECTION THROUGH HOST IN THE MIDDLE
ssh -t reachable_host ssh unreachable_host

Unreachable_host is unavailable from local network, but it’s available from reachable_host’s network. This command creates a connection to unreachable_host through “hidden” connection to reachable_host.

7) COPY FROM HOST1 TO HOST2, THROUGH YOUR HOST
ssh root@host1 “cd /somedir/tocopy/ && tar -cf – .” | ssh root@host2 “cd /samedir/tocopyto/ && tar -xf -”

Good if only you have access to host1 and host2, but they have no access to your host (so ncat won’t work) and they have no direct access to each other.

8) RUN ANY GUI PROGRAM REMOTELY
ssh -fX @

The SSH server configuration requires:

X11Forwarding yes # this is default in Debian

And it’s convenient too:

Compression delayed

9) CREATE A PERSISTENT CONNECTION TO A MACHINE
ssh -MNf @

Create a persistent SSH connection to the host in the background. Combine this with settings in
your ~/.ssh/config:
Host host
ControlPath ~/.ssh/master-%r@%h:%p
ControlMaster no

All the SSH connections to the machine will then go through the persisten SSH socket. This is very useful if you are using SSH to synchronize files (using rsync/sftp/cvs/svn) on a regular basis because it won’t create a new socket each time to open an ssh connection.

10) ATTACH SCREEN OVER SSH
ssh -t remote_host screen -r

Directly attach a remote screen session (saves a useless parent bash process)

11) PORT KNOCKING!
knock 3000 4000 5000 && ssh -p user@host && knock 5000 4000 3000

Knock on ports to open a port to a service (ssh for example) and knock again to close the port. You have to install knockd.
See example config file below.
[options]
logfile = /var/log/knockd.log
[openSSH]
sequence = 3000,4000,5000
seq_timeout = 5
command = /sbin/iptables -A INPUT -i eth0 -s %IP% -p tcp –dport 22 -j ACCEPT
tcpflags = syn
[closeSSH]
sequence = 5000,4000,3000
seq_timeout = 5
command = /sbin/iptables -D INPUT -i eth0 -s %IP% -p tcp –dport 22 -j ACCEPT
tcpflags = syn

12) REMOVE A LINE IN A TEXT FILE. USEFUL TO FIX
ssh-keygen -R

In this case it’s better do to use the dedicated tool
13) RUN COMPLEX REMOTE SHELL CMDS OVER SSH, WITHOUT ESCAPING QUOTES

ssh host -l user $(> ~/.ssh/authorized_keys”

If you use Mac OS X or some other *nix variant that doesn’t come with ssh-copy-id, this one-liner will allow you to add your public key to a remote machine so you can subsequently ssh to that machine without a password.

17) LIVE SSH NETWORK THROUGHPUT TEST
yes | pv | ssh $host “cat > /dev/null”

connects to host via ssh and displays the live transfer speed, directing all transferred data to
/dev/null
needs pv installed
Debian: ‘apt-get install pv’
Fedora: ‘yum install pv’ (may need the ‘extras’ repository enabled)

18) HOW TO ESTABLISH A REMOTE GNU SCREEN SESSION THAT YOU CAN RE-CONNECT TO
ssh -t user@some.domain.com /usr/bin/screen -xRR

Long before tabbed terminals existed, people have been using Gnu screen to open many shells in a single text terminal. Combined with ssh, it gives you the ability to have many open shells with a single remote connection using the above options. If you detach with “Ctrl-a d” or if the ssh session is accidentally terminated, all processes running in your remote shells remain undisturbed, ready for you to reconnect. Other useful screen commands are “Ctrl-a c” (open new shell) and “Ctrl-a a” (alternate between shells). Read this quick reference for more screen commands: http://aperiodic.net/screen/quick_reference

19) RESUME SCP OF A BIG FILE
rsync –partial –progress –rsh=ssh $file_source $user@$host:$destination_file

It can resume a failed secure copy ( usefull when you transfer big files like db dumps through vpn ) using rsync.
It requires rsync installed in both hosts.
rsync –partial –progress –rsh=ssh $file_source $user@$host:$destination_file local -> remote
or
rsync –partial –progress –rsh=ssh $user@$host:$remote_file $destination_file remote -> local

20) ANALYZE TRAFFIC REMOTELY OVER SSH W/ WIRESHARK
ssh root@server.com ‘tshark -f “port !22″ -w -’ | wireshark -k -i -

This captures traffic on a remote machine with tshark, sends the raw pcap data over the ssh link, and displays it in wireshark. Hitting ctrl+C will stop the capture and unfortunately close your wireshark window. This can be worked-around by passing -c # to tshark to only capture a certain # of packets, or redirecting the data through a named pipe rather than piping directly from ssh to wireshark. I recommend filtering as much as you can in the tshark command to conserve bandwidth. tshark can be replaced with tcpdump thusly:
ssh root@example.com tcpdump -w – ‘port !22′ | wireshark -k -i -

21) HAVE AN SSH SESSION OPEN FOREVER
autossh -M50000 -t server.example.com ‘screen -raAd mysession’

Open a ssh session opened forever, great on laptops losing Internet connectivity when switching WIFI spots.

22) HARDER, FASTER, STRONGER SSH CLIENTS
ssh -4 -C -c blowfish-cbc

We force IPv4, compress the stream, specify the cypher stream to be Blowfish. I suppose you could use aes256-ctr as well for cypher spec. I’m of course leaving out things like master control sessions and such as that may not be available on your shell although that would speed things up as well.

23) THROTTLE BANDWIDTH WITH CSTREAM
tar -cj /backup | cstream -t 777k | ssh host ‘tar -xj -C /backup’

this bzips a folder and transfers it over the network to “host” at 777k bit/s.
cstream can do a lot more, have a look http://www.cons.org/cracauer/cstream.html#usage
for example:
echo w00t, i’m 733+ | cstream -b1 -t2

24) TRANSFER SSH PUBLIC KEY TO ANOTHER MACHINE IN ONE STEP
ssh-keygen; ssh-copy-id user@host; ssh user@host

This command sequence allows simple setup of (gasp!) password-less SSH logins. Be careful, as if you already have an SSH keypair in your ~/.ssh directory on the local machine, there is a possibility ssh-keygen may overwrite them. ssh-copy-id copies the public key to the remote host and appends it to the remote account’s ~/.ssh/authorized_keys file. When trying ssh, if you used no passphrase for your key, the remote shell appears soon after invoking ssh user@host.

25) COPY STDIN TO YOUR X11 BUFFER
ssh user@host cat /path/to/some/file | xclip

Have you ever had to scp a file to your work machine in order to copy its contents to a mail? xclip can help you with that. It copies its stdin to the X11 buffer, so all you have to do is middle-click to paste the content of that looong file :)

Have Fun
source : http://www.subhashdasyam.com/2011/05/25-best-ssh-commands-tricks.html

7 Linux Shells Using Built-in Tools



There are many distributions of linux, and they all do things a little different regarding default security and built-in tool sets. Which means when engaging these different flavors during a pentest, what works against one linux target to get an interactive shell, may not work against another. Well, not to worry my friends, there are many techniques for spawning shells, specifically reverse shells, from linux, and one or more of these techniques is bound to be available no matter which distro you’re looking at.

The scenario is this: You have the ability to run a simple command, or cause a user to run a simple command, on the target system. Whether it be via a Remote Command Execution vulnerability in a website, or some sort of php injected XSS which causes a privileged user to run commands on the target system. There are many instances of this scenario. Starting from the easiest and most common, here are some of the techniques which can be used to gain reverse shell on the target system.

#1. netcat:
Surprise!!! Nothing new here. Plain and simple. Fire up a listener on the attacker machine on a port which is reachable from the target and connect back to the listener with netcat. Looks like this.



…just kidding…



#2. netcat with GAPING_SECURITY_HOLE disabled:
This is a little trick that Ed Skoudis tweeted about in November of last year, but I haven’t seen it widely publicized. It is based on the common technique used to build netcat relays. When the GAPING_SECURITY_HOLE is disabled, which means you don’t have access to the ‘-e’ option of netcat, most people pass on using netcat and move to something else. Well this just isn’t necessary. Create a FIFO file system object and use it as a backpipe to relay standard output from commands piped from netcat to /bin/bash back into netcat. Sounds confusing right? The following image should clear things up.



#3. netcat without netcat:
I love “hacks” that use features of the operating system against itself. This is one of those “hacks”. It takes the /dev/tcp socket programming feature and uses it to redirect /bin/bash to a remote system. It’s not always available, but can be quite handy when it is.



#4. netcat without netcat or /dev/tcp:
/dev/tcp not available either? Just use telnet with technique #2.



telnet-to-telnet:
I’m not sure why you’d use this technique, but it’s an option, so here it is nonetheless. This is clearly the ugliest of the techniques. This technique uses two telnet sessions connected to remote listeners to pipe input from one telnet session to /bin/bash, and pipe the output to the second telnet session. Commands are entered into one the of the attackers listeners and feedback is received on the other.



#6. RCE shell:
On this one I’m cheating a little bit. This applies to Remote Command Execution vulnerabilities only. Rather than manually enter commands into a proxy or browser url, I wrote small python script which gives you the feel of a shell, without spawning anything in reverse from the target. You merely pass the script the vulnerable url with the injectable field replaced with the ‘<rce>’ tag and it presents you with a clean interface for entering commands. In the background, the script is making the request to the web server, parsing the response, and presenting it to you.



#7. PHP reverse shell via interactive console:
The last technique makes use of the php interactive console. The attacker issues one command which moves to the /tmp directory (because it is typically world writable), uses wget to download a malicious php reverse_tcp backdoor (which the attacker hosts on a web server that he controls), and executes the backdoor via the interactive console.



I want to end this post by stating that I am not the originator of techniques #1, 2, 3, 5, or 7. The majority of these techniques were learned in Ed Skoudis’ amazing Security 504 and 560 classes available through SANS. Technique #4 is something I’ve never seen but stumbled across as I was conducting the demos for this post, so I’ll take credit. Obviously, anyone can do #6, and there are plugins for various automated web app testing software packages that do, but I built my script from the ground up and tailored it to preference. If you know of any additional methods that may be helpful to the pentesting community, please leave in the comments below. Without sharing, we all fail. Thanks, and enjoy!

Source : http://lanmaster53.com/2011/05/7-linux-shells-using-built-in-tools/

Installing EHCP (Easy Hosting Control Panel)

EHCP is a powerful, yet easy to install control panel that allows the user to manage services such as Web, FTP, Database and DNS servers.

The install script handles the installation and configuration of the required services. I recommend starting with a clean Debian system to avoid conflicts.

1. Download required EHCP files

wget http://www.ehcp.net/download


2. Uncompress the files

tar zxvf ehcp_latest.tgz


3. Move into the install directory and run the install script

cd ehcp
./install.sh


Read the instructions carefully, your server will send statistical information to the EHCP developers. If you choose to move on, the install script will install all required packages including Apache, MySql and Postfix. You will need to provide some information to configure the services and set the admin passwords.

4. When the installer is finished, enter the control panel using: http://yourserver.

Installing HAVP (HTTP Antivirus Proxy)

HAVP (HTTP Antivirus Proxy) is a proxy with a ClamAV anti-virus scanner. The main aims are continuous, non-blocking downloads and smooth scanning of dynamic and password protected HTTP traffic. Havp antivirus proxy has a parent and transparent proxy mode. It can be used with squid or standalone.

1. Install HAVP

apt-get install havp


2. Start HAVP if it didn't start after the installation

/etc/init.d/havp start


It's ready, by default HAVP listens on port 8080. You can configure your web browser to use the server as a proxy.

You can customize the error pages by editing the html files in this directory: /etc/havp/templates/en/

Pure-FTPd with MySQL backend

Pure-FTPd is a free, secure, production-quality and standard-conformant FTP server. It doesn't provide useless bells and whistles, but focuses on efficiency and ease of use. It provides simple answers to common needs, plus unique useful features for personal users as well as hosting providers.

In this tutorial we'll install Pure-FTPd with MySQL backend.

Install Pure-FTPd with mysql backend
apt-get install pure-ftpd-mysql


Create user and group used to run the ftp server
groupadd -g 2001 ftpgroup
useradd -u 2001 -s /bin/false -d /bin/null -c "pureftpd user" -g ftpgroup ftpuser


Create database and a table that will store user information
mysql -u root -p
GRANT SELECT ON ftpd.* TO vhosts@localhost IDENTIFIED BY 'mypasswd';
FLUSH PRIVILEGES;
CREATE DATABASE ftpd;
USE ftpd;

CREATE TABLE users (
user varchar(30) NOT NULL,
password varchar(64) NOT NULL,
home varchar(128) NOT NULL,
bandwidth_limit_upload smallint(5) NOT NULL default 0,
bandwidth_limit_download smallint(5) NOT NULL default 0,
ip_allow varchar(15) NOT NULL default 'any',
quota smallint(5) NOT NULL default '0',
quota_files int(11) NOT NULL default 0,
active enum('yes','no') NOT NULL default 'yes',
PRIMARY KEY (user),
UNIQUE KEY User (user)
) TYPE=MyISAM;

INSERT INTO users (user, password, home) VALUES ('username', MD5('mypasswd'), '/home/username');

quit;


You will be able to control bandwidth limits and quotas for each user. Using zero for these fields will allow unlimited use of resources. The bandwidth limits are specified in KB/s and the quota in MB.

Configure Pure-ftpd (pico /etc/pure-ftpd/db/mysql.conf). Remove everything from the default configuration file and add these lines:
MYSQLSocket /var/run/mysqld/mysqld.sock
MYSQLUser vhosts
MYSQLPassword mypasswd
MYSQLDatabase ftpd
MYSQLCrypt md5
MYSQLDefaultUID 2001
MYSQLDefaultGID 2001
MYSQLGetPW SELECT password FROM users WHERE user = "\L" AND active = "yes" AND (ip_allow = "any" OR ip_allow LIKE "\R")
MYSQLGetDir SELECT home FROM users WHERE user = "\L"AND active = "yes" AND (ip_allow = "any" OR ip_allow LIKE "\R")
MySQLGetBandwidthUL SELECT bandwidth_limit_upload FROM users WHERE user = "\L"AND active = "yes" AND (ip_allow = "any" OR ip_allow LIKE "\R")
MySQLGetBandwidthDL SELECT bandwidth_limit_download FROM users WHERE user = "\L"AND active = "yes" AND (ip_allow = "any" OR ip_allow LIKE "\R")
MySQLGetQTASZ SELECT quota FROM users WHERE user = "\L"AND active = "yes" AND (ip_allow = "any" OR ip_allow LIKE "\R")
MySQLGetQTAFS SELECT quota_files FROM users WHERE user = "\L"AND active = "yes" AND (ip_allow = "any" OR ip_allow LIKE "\R")


Create these simple text files that will force the server to create home directories for users if they don't exist and chroot the user to it's home directory:

pico /etc/pure-ftpd/conf/ChrootEveryone
yes


pico /etc/pure-ftpd/conf/CreateHomeDir
yes


Since we are using pure-ftpd-mysql insted of pure-ftpd, make the following change (pico /usr/sbin/pure-ftpd-wrapper):
my $daemon = '/usr/sbin/pure-ftpd-mysql';


Restart Pure-ftpd
/etc/init.d/pure-ftpd-mysql restart


We're all done. You should be able to make connections to the servers with your favorite FTP client.

--

Update - 29th October 2008

I've had problems with debian-minimal installations where the ftp server simply won't start and doesn't leave any trace in the log files. To fix that I had to make one minor change to the inetd config file (pico /etc/inetd.conf):

ftp stream tcp nowait root /usr/sbin/tcpd /usr/sbin/pure-ftpd-mysql


Open the config file and in the ftp line, change pure-ftpd-wrapper to pure-ftpd-mysql

When done, restart inetd:

/etc/init.d/openbsd-inetd restart


--

Update - 20th April 2010

In lenny, use this command to restart the service or change the variable STANDALONE_OR_INETD to standalone in /etc/default/pure-ftpd-common:

/etc/init.d/openbsd-inetd restart

Installing and configuring PPTP VPN server on lenny

If you would like to setup a Virtual Private Network (VPN) for Windows clients, PPTP is a great choice. It's easy to set up on the server and you don't need any additional software for the Windows clients to connect.

1. Install the required packages

apt-get install pptpd


2. Configure the IP range assigned to clients (pico /etc/pptpd.conf)

localip 192.168.1.2
remoteip 192.168.1.10-20


Using this config the clients are assigned any IP address between and including 192.168.1.10 and 192.168.1.20.

3. Restart the PPTP daemon

/etc/init.d/pptpd restart


4. Create a user allowed to connect (pico /etc/ppp/chap-secrets)

user1 pptpd secretpassword *


Passwords are not encrypted. This allows the a user with the username: user1 and the password: secretpassword to login from any ip address.

5. Enable IP forward at startup to allow the VPN clients to connect to the server's local network. (pico /etc/sysctl.conf)

net.ipv4.ip_forward=1


Also run this command to activate the IP forward instantly:

echo 1 > /proc/sys/net/ipv4/ip_forward


6. Create a routing rule to allow the VPN clients to route network traffic through the server.

iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE


Read this tutorial to learn how to create iptables rules on startup:

Loading iptables rules on startup

 
2012 upshell | Header Image by Game Wallpapers
Avatar Gamezine Designed by Cheapest Tablet PC
Supported by Phones 4u