Fidcer'Blog

centos 6.5 自动配置vsftp http dns

字数统计: 1.6k阅读时长: 9 min
2019/02/21 Share
环境:centos6.5 配置本地yum源

python2.7
[vplayer url=”http://122.228.238.158/vhot2.qqvideo.tc.qq.com/AOREL4WspnvAOiKO2cu7iWM8_Jkp7CQb0aobV2cmLjNE/r0604x83i0v.mp4?sdtfrom=v1010&guid=6ca265bc1a779fedafa760ae8c67e970&vkey=9769DF585EE830B610269355CBFC259995D4ABA72034F79CA48EDB29EF38A798C6385ED8D040CD7C87F50045F7DDE1CCA7E48EE1C6756C4FCF166B7B280D8E3B27A984E4C5A2867DABDC6B347F0F38BA2E9990D0F68E7E4E61BAB188EB0E6FDD305FB63483D569E29E37DC016CC4DDB87BFAA9DC97E78070" /]

使用方法:
1.首先使用第ws2018生成出用户和密码
命令:python ws2018.py -i [IP段] -n [多少用户]
python ws2018.py -i 192.168.1.1-192.168.1.10 -n 10
2.运行setservice

自动生成用户,ip脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python
#coding=utf-8

import optparse
import random

parse = optparse.OptionParser(usage="usage: %prog [options] args",version="1.1") #用optparse库设置参数
parse.add_option('-n',dest='number',type=int,help='Student station number')
parse.add_option('-i',dest='ip_addr',type=str,help='IP ADDRESS')
options,args=parse.parse_args()
print 'Example:python ws2018.py -n 5 -i 192.168.1.1-192.168.1.5'


def ip2num(ip): #ip地方范围
ips = [int(x) for x in ip.split('.')]
return ips[0]<< 24 | ips[1]<< 16 | ips[2] << 8 | ips[3]
def num2ip (num):
return '%s.%s.%s.%s' % ((num >> 24) & 0xff, (num >> 16) & 0xff, (num >> 8) & 0xff, (num & 0xff))
#return '%s.%s.%s.%s' % ((num & 0xff000000)>>24,(num & 0x00ff0000)>>16,(num & 0x00000ff00)>>8,num & 0x000000ff)
def gen_ip(ip):
start ,end = [ip2num(x) for x in ip.split('-')]
return [num2ip(num) for num in range(start,end+1) if num & 0xff]

Ip = gen_ip(options.ip_addr)
opt_num = options.number + 1


for g_number in range(1,opt_num):

def salt(num):
ws_id = "ws" + str(g_number)

for salt_num in range(num):
str_int = "qwertyuiopasdfghjkzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM" #随机生成8位密码
sa = []
for i in range(8):
sa.append(random.choice(str_int))
salt = ''.join(sa)

test1 = "%s,%d,%s,%s,%s" % (ws_id,g_number,ws_id,salt,Ip[g_number-1])


print test1

a = open('./ws2018.csv','a')
a.write("%s\n"%test1)
a.close()
salt_number = salt(1)






#ip_dest = IPy.IP("%s" % str(options.ip_addr)) # 生成ip
#for ip_ADDR in ip_dest:
# print ip_ADDR

vsftp虚拟用户脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import os
import re
import csv


def ftp():
cmd_yum = os.system('yum install vsftpd db_load httpd -y')
with open('ws2018.csv','rb') as f:
reader = csv.reader(f)
for row in reader:
vsuser = open("/etc/vsftpd/vsftpuser.txt",'a')
vsuser.write("%s\n%s\n"%(row[2],row[3]))
vsuser.close()
vsf_make = os.system('mkdir -p /etc/user_dir_config')
vsf_touch = os.system("touch /etc/user_dir_config/%s"%row[2])
vsf_write = open("/etc/user_dir_config/%s"%row[2],'w')
vsf_payload0 = "anon_world_readable_only=NO"
vsf_payload1 = "anon_upload_enable=YES"
vsf_payload2 = "anon_mkdir_write_enable=YES"
vsf_payload3 = "anon_other_write_enable=YES"
vsf_payload4 = "local_root=/mnt/ftp/%s"%row[2]
vsf_payload5 = "write_enable=YES"

vsf_write.write("%s\n%s\n%s\n%s\n%s\n%s\n"%(vsf_payload5,vsf_payload0,vsf_payload1,vsf_payload2,vsf_payload3,vsf_payload4))
vsf_userhome = os.system("mkdir -p /mnt/ftp/%s"%row[2])
vsf_chmod = os.system("chmod 777 /mnt/ftp/%s"%row[2])

cmd_iptable = os.system ('iptables -F && service iptables save && setenforce 0')

cmd_load = os.system('db_load -T -t hash -f /etc/vsftpd/vsftpuser.txt /etc/vsftpd/vsftpuser.db && chmod 600 /etc/vsftpd/vsftpuser.db')
cmd_pam1 = os.system ('cp /etc/pam.d/vsftpd /etc/pam.d/vsftpd.back')
pam_write = open("/etc/pam.d/vsftpd",'w')
pam_payload1 = "auth required /lib64/security/pam_userdb.so db=/etc/vsftpd/vsftpuser"
pam_payload2 = "account required /lib64/security/pam_userdb.so db=/etc/vsftpd/vsftpuser"
pam_payload0 = "#%PAM-1.0"
pam_write.write("%s\n%s\n%s\n" %(pam_payload0,pam_payload1,pam_payload2))
pam_write.close()
cp_vsfconf = os.system("cp /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf.back")
vsf_conf = os.system("sed -i 's/anonymous_enable=YES/anonymous_enable=NO/g' /etc/vsftpd/vsftpd.conf")
vsf_conf = os.system("sed -i 's/#chroot_local_user=YES/chroot_local_user=YES/g' /etc/vsftpd/vsftpd.conf" )
vsfconf_write = open("/etc/vsftpd/vsftpd.conf","a")
vsfconf_write.write("\n%s\n%s\n%s\n"%('guest_enable=YES','guest_username=ftpload','user_config_dir=/etc/user_dir_config'))
vsf_user = os.system('useradd -s /sbin/nologin ftpload')
vsf_chmoduser = os.system('chmod a-w /home/ftpload')
vsf_chkconfig = os.system('chkconfig --level 2345 vsftpd on')
selinux_start = os.system("sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config")

#vsf_conf = os.system("sed -i 's/chroot_local_user=NO/chroot_local_user=YES/g' /etc/vsftpd/vsftpd.conf" )
#server_vsftp1 = os.system("service vsftpd restart")
ftp()
server_vsftp = os.system("service vsftpd start")

print "You Service Start The Success"
'''
vsconf = open("/etc/vsftpd/vsftpd.conf",'a')
vsconf_py = "%s\r\n%s"%(guest_enable=yes,)
vsconf.write(str("guest_enable=yes\r\n"))
'''

配置dns

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import os
import csv

def dns(local_ip):
main_path = '/var/named/chroot/etc/named.conf'
rfc_path = '/var/named/chroot/etc/named.rfc1912.zones'
quyu_path = '/var/named/chroot/var/named'
quyu_path1 = '/var/named/chroot/var/named/chinaskills.com.zone'
dns_yum = os.system("yum install bind bind-utils bind-chroot -y")
dns_cpconf = os.system("cp /etc/named.* /var/named/chroot/etc/. && cp /var/named/named.* %s/."%quyu_path)
dns_maincf = os.system("sed -i 's/127.0.0.1/any/g' %s"%main_path)
dns_maincf2 = os.system("sed -i 's/listen-on-v6/#listen-on-v6/g' %s"%main_path)
dns_maincf3 = os.system("sed -i 's/localhost;/any;/g' %s"%main_path)
dns_maincf4 = os.system("sed -i 's/dnssec-enable yes/dnssec-enable no/g' %s"%main_path)
dns_maincf5 = os.system("sed -i 's/dnssec-validation yes/dnssec-validation no/g' %s"%main_path)
dnsrfc_payload1 = "zone \"chinaskills.com\" IN {"
dnsrfc_payload2 = "type master;"
dnsrfc_payload3 = "file \"chinaskills.com.zone\";"
dnsrfc_payload4 = "allow-update { none; };\n};"
dnsrfc_write = open("%s"%rfc_path,'a')
dnsrfc_write.write("\n%s\n%s\n%s\n%s\n"%(dnsrfc_payload1,dnsrfc_payload2,dnsrfc_payload3,dnsrfc_payload4))
dnsrfc_write.close()
dns_touch = os.system("cp %s/named.empty %s/chinaskills.com.zone"%(quyu_path,quyu_path))
dns_quyu = os.system("sed -i 's/@ rname.invalid./dns.chinaskills.com. root.chinaskills.com./g' %s"%quyu_path1)
for i in range(1,4):
dns_quyu1 = os.system("sed -i '8d' %s"%quyu_path1)
dns_payload = ' '*8+'NS'+' '*4+'dns.chinaskills.com.'
dns_payload1 = 'dns'+' '*4+'A'+4*' '+str(local_ip)
dnsqy_write = open("%s"%quyu_path1,'a')
dnsqy_write.write("%s\n%s"%(dns_payload,dns_payload1))
dnsqy_write.close()
with open('ws2018.csv','rb') as f:
reader = csv.reader(f)
for row in reader:
dnsqy1_open = open("%s"%quyu_path1,'a')
dnsqy1_open.write("\n%s A %s\n"%(row[0],row[4]))
dnsqy1_open.close()
dnschown = os.system("chown -R named:named /var/named/chroot")
dns_chkconfig = os.system('chkconfig --level 2345 named on')



dns('192.168.1.1')
dns_server = os.system("service named start")

配置http

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import csv
import os

def http():
http_pyvirt = ['<VirtualHost *:80>','ServerAdmin root@chinaskills.com','DocumentRoot','ServerName'\
,'</VirtualHost>']
http_pydire = ['<Directory "/">','Options FollowSymLinks','AllowOverride None','Order allow,deny','Allow from all',\
'</Directory>']
hp_mp = "/etc/httpd/conf/httpd.conf"
hp_uspt = "/etc/httpd/conf.d"
http_yum = os.system('yum install httpd -y')
http_sed = os.system("sed -i 's/#NameVirtualHost/NameVirtualHost/g' %s"%hp_mp)
with open('ws2018.csv','rb') as f:
reader = csv.reader(f)
for row in reader:
hp_ftppt = "/mnt/ftp/%s"%row[0]
hp_user = "%s.chinaskills.com"%row[0]
hp_ip = "allow from %s"%row[4]
hp_touch = os.system("touch %s/%s.conf"%(hp_uspt,row[0]))
hp_sed1 = os.system("sed -i 's/User apache/User ftpload/g' %s"%hp_mp)
hp_sed2 = os.system("sed -i 's/Group apache/Group ftpload/g' %s"%hp_mp)
http_open = open("%s/%s.conf"%(hp_uspt,row[0]),'a')
http_open.write("%s\n%s\n%s %s\n%s %s\n%s\n%s\n%s\n%s\n%s\n%s\n%s"%(http_pyvirt[0],http_pyvirt[1],http_pyvirt[2],hp_ftppt,\
http_pyvirt[3],hp_user,http_pydire[0],http_pydire[1],http_pydire[2],http_pydire[3],hp_ip,http_pydire[5],http_pyvirt[4]))
http_open.close()


http()
http_start = os.system("service httpd start")
http_chkconfig = os.system("chkconfig --level 2345 httpd on")
CATALOG