def wrapfile(self, elem): if type(elem) == dict and "_customtype" in elem: if elem["_customtype"] == "file": newname = self.newfile(elem["filename"]) if "content" not in elem: shutil.move(os.path.join(elem["location"]), newname) return File(newname, elem["filename"]) else: open(newname, "w").write(elem["content"]) return File(newname, newname) else: return None
def configure_umask(): """5.4.3, 5.4.4""" umask_reg = r'^(\s*)umask\s+[0-7]+(\s*)$' bashrc = exec_shell([ 'cat /etc/bashrc | sed -E "s/{}/\\1umask 027\\2/g"'.format(umask_reg) ]) File('/etc/bashrc').write(bashrc) profile = exec_shell([ 'cat /etc/profile | sed -E "s/{}/\\1umask 027\\2/g"'.format(umask_reg) ]) File('/etc/profile').write(profile)
def configure_warning_banners(): """1.7 Warning Banners""" # 1.7.1 Command Line Warning Banners exec_shell([ 'update-motd --disable', 'chown root:root /etc/motd', 'chmod 644 /etc/motd' ]) File('/etc/motd').write(get_string_asset('/etc/motd')) exec_shell(['chown root:root /etc/issue', 'chmod 644 /etc/issue']) File('/etc/issue').write('Authorized uses only. All activity may be monitored and reported.\n') exec_shell(['chown root:root /etc/issue.net', 'chmod 644 /etc/issue.net']) File('/etc/issue.net').write('Authorized uses only. All activity may be monitored and reported.\n')
def configure_mac(): """1.6. Mandatory Access Control""" Package('selinux-policy').install() Package('selinux-policy-targeted').install() Package('policycoreutils-python').install() kernel=exec_shell([ 'cat /boot/grub/menu.lst | grep ^kernel' ]) # add selinux=1 if not 'selinux' in kernel: boot = exec_shell([ 'cat /boot/grub/menu.lst | sed -E "s/^(kernel.*)$/\\1 selinux=1/"' ]) else: boot = exec_shell([ 'cat /boot/grub/menu.lst | sed -E "s/(selinux)=0/\\1=1/g"' ]) File('/boot/grub/menu.lst').write(boot) # add security=selinux if not 'security' in kernel: boot = exec_shell([ 'cat /boot/grub/menu.lst | sed -E "s/^(kernel.*)$/\\1 security=selinux/"' ]) else: boot = exec_shell([ 'cat /boot/grub/menu.lst | sed -E "s/^(kernel.*security=)[^ ]*(.*)/\\1selinux\\2/g"' ]) File('/boot/grub/menu.lst').write(boot) boot = exec_shell([ 'cat /boot/grub/menu.lst | sed -E "s/(enforcing)=0/\\1=1/g"' ]) File('/boot/grub/menu.lst').write(boot) exec_shell([ 'echo "SELINUX=enforcing\nSELINUXTYPE=targeted" > /etc/selinux/config', 'chown root:root /etc/selinux/config', 'chmod 0600 /etc/selinux/config', 'touch /.autorelabel' ])
def main(): global suffix while True: userinput = userInput() # From user input makes "command args "line args" -kwargs value -kwargs "line value" command, args, kwargs = getArgs(userinput) print(command) print(args) print(kwargs) if command == "help": # Variables detected if len(args) != 0 or len(kwargs) != 0: pass print("?" + "-"*10 + "Help" + "-"*10 + "?") print("1) ") commands = {"file": File()} if command == "file": file = commands[command] file.changeFile("C:\\Users\\Artur\\Documents\\GitHub\\Server\\Python_Projects\\circleGenerator.py") file.cmdPrintFile()
def configure_su(): """5.5 Ensure access to the su command is restricted""" File('/etc/pam.d/su').write(get_string_asset('/etc/pam.d/su')) exec_shell('usermod -aG wheel root')
import pytest from find_kedro import find_kedro from util import File, make_files_and_cd content = [ ( 2, ["node*"], [ File( "nodes/nodes.py", """\ from kedro.pipeline import node node_a_b = node(lambda x: x, "a", "b", name="a_b") node_b_c = node(lambda x: x, "b", "c", name="b_c") """, ) ], ), ( 2, ["dont_match", 1, 1.1, 0.123, "node*"], [ File( "nodes/nodes.py", """\ from kedro.pipeline import node
def test_adv(self): # 遍历文件生成数组 fileUtil = File.ReadFile() testpath = r"D:\work" fileList = fileUtil.getFileList(testpath, []) # 上传文件到cos for e in fileList: tecentUtil.uploadImg(e[1], e[0]) # 生成测试数据 imgList = tecentUtil.getImgList(fileList) # 循环请求 for e in imgList: print(e) imgUrl = e[1] testCase = e[0] url = baseUrl + "/index.php?c=goods" cmd = "11552" data = { "json": [{ "cmd": cmd, "type": 0, "image_url": imgUrl, "user_id": user_id, "user_name": user_name, "token": token }] } # headers = constant.env["headers"] print( cmd + testCase + "url:" + url, ",request data:" + str(data).replace("\'", "\"").replace(r"\\", "\\")) j = httpUtil.postJson(url, data, headers) js = j[cmd] exc.writeXls(path, [ cmd, e[0], js["statusCode"], js["qtime"], js["errorMsg"], url, str(data).replace("\'", "\"").replace(r"\\", "\\") ]) if js["statusCode"] != 0: break # 上传图片至图谱获取返回结果 try: tpUrl = "http://test-api2.ppwang.com:8800/index.php?c=test&m=requestTupuCheakTest&type=0&imageUrl=" + e[ 1] res = requests.get(tpUrl) r = str((res.text)[:-5]) js = json.loads(r) js = json.loads(js["json"]) tpData = [] if js["56a8645b0c800bff40990cf1"]["statistic"] != None: tpData.append( ["广告识别", js["56a8645b0c800bff40990cf1"]["statistic"]]) if js["5acb135cc40c6772b10ec73a"]["statistic"] != None: tpData.append( ["暴恐识别", js["5acb135cc40c6772b10ec73a"]["statistic"]]) if js["54bcfc6c329af61034f7c2fc"]["statistic"] != None: tpData.append( ["色情识别", js["54bcfc6c329af61034f7c2fc"]["statistic"]]) exc.writeXls(path, [ "。", e[0], str(res.status_code), "。", "。", str(tpUrl), str(tpData) ]) exc.writeXls(path, [""]) time.sleep(1) except Exception as e: print(e)
""" import pytest from find_kedro import find_kedro from util import File, make_files_and_cd content = [ ( "onefile", 2, [ File( "nodes/nodes.py", """\ from kedro.pipeline import node node_a_b = node(lambda x: x, "a", "b", name="a_b") node_b_c = node(lambda x: x, "b", "c", name="b_c") """, ) ], ), ( "deeply nested file", 2, [ File( "nodes/that/are/deeply/nested/without/any/init/nodes.py", """\ from kedro.pipeline import node
def configure_auditd(): """4.1.1 Configure Data Retention""" PropertyFile('/etc/audit/auditd.conf', ' = ').override({ 'max_log_file': '8', 'space_left_action': 'email', 'action_mail_acct': 'root', 'admin_space_left_action': 'halt', 'max_log_file_action': 'keep_logs' }).write() kernel=exec_shell([ 'cat /boot/grub/menu.lst | grep ^kernel' ]) # add audit=1 if not 'audit' in kernel: boot = exec_shell([ 'cat /boot/grub/menu.lst | sed -E "s/^(kernel.*)$/\\1 audit=1/"' ]) else: boot = exec_shell([ 'cat /boot/grub/menu.lst | sed -E "s/(audit)=0/\\1=1/g"' ]) File('/boot/grub/menu.lst').write(boot) audit_rules = """-D -b 320 -a always,exit -F arch=b64 -S adjtimex -S settimeofday -k time-change -a always,exit -F arch=b32 -S adjtimex -S settimeofday -S stime -k time-change -a always,exit -F arch=b64 -S clock_settime -k time-change -a always,exit -F arch=b32 -S clock_settime -k time-change -w /etc/localtime -p wa -k time-change -w /etc/group -p wa -k identity -w /etc/passwd -p wa -k identity -w /etc/gshadow -p wa -k identity -w /etc/shadow -p wa -k identity -w /etc/security/opasswd -p wa -k identity -a always,exit -F arch=b64 -S sethostname -S setdomainname -k system-locale -a always,exit -F arch=b32 -S sethostname -S setdomainname -k system-locale -w /etc/issue -p wa -k system-locale -w /etc/issue.net -p wa -k system-locale -w /etc/hosts -p wa -k system-locale -w /etc/sysconfig/network -p wa -k system-locale -w /etc/sysconfig/network-scripts/ -p wa -k system-locale -w /etc/selinux/ -p wa -k MAC-policy -w /usr/share/selinux/ -p wa -k MAC-policy -w /var/log/lastlog -p wa -k logins -w /var/run/faillock/ -p wa -k logins -w /var/run/utmp -p wa -k session -w /var/log/wtmp -p wa -k logins -w /var/log/btmp -p wa -k logins -a always,exit -F arch=b64 -S chmod -S fchmod -S fchmodat -F auid>=500 -F auid!=4294967295 -k perm_mod -a always,exit -F arch=b32 -S chmod -S fchmod -S fchmodat -F auid>=500 -F auid!=4294967295 -k perm_mod -a always,exit -F arch=b64 -S chown -S fchown -S fchownat -S lchown -F auid>=500 -F auid!=4294967295 -k perm_mod -a always,exit -F arch=b32 -S chown -S fchown -S fchownat -S lchown -F auid>=500 -F auid!=4294967295 -k perm_mod -a always,exit -F arch=b64 -S setxattr -S lsetxattr -S fsetxattr -S removexattr -S lremovexattr -S fremovexattr -F auid>=500 -F auid!=4294967295 -k perm_mod -a always,exit -F arch=b32 -S setxattr -S lsetxattr -S fsetxattr -S removexattr -S lremovexattr -S fremovexattr -F auid>=500 -F auid!=4294967295 -k perm_mod -a always,exit -F arch=b64 -S creat -S open -S openat -S truncate -S ftruncate -F exit=-EACCES -F auid>=500 -F auid!=4294967295 -k access -a always,exit -F arch=b32 -S creat -S open -S openat -S truncate -S ftruncate -F exit=-EACCES -F auid>=500 -F auid!=4294967295 -k access -a always,exit -F arch=b64 -S creat -S open -S openat -S truncate -S ftruncate -F exit=-EPERM -F auid>=500 -F auid!=4294967295 -k access -a always,exit -F arch=b32 -S creat -S open -S openat -S truncate -S ftruncate -F exit=-EPERM -F auid>=500 -F auid!=4294967295 -k access -a always,exit -F arch=b64 -S mount -F auid>=500 -F auid!=4294967295 -k mounts -a always,exit -F arch=b32 -S mount -F auid>=500 -F auid!=4294967295 -k mounts -a always,exit -F arch=b64 -S unlink -S unlinkat -S rename -S renameat -F auid>=500 -F auid!=4294967295 -k delete -a always,exit -F arch=b32 -S unlink -S unlinkat -S rename -S renameat -F auid>=500 -F auid!=4294967295 -k delete -w /etc/sudoers -p wa -k scope -w /etc/sudoers.d/ -p wa -k scope -w /var/log/sudo.log -p wa -k actions -w /sbin/insmod -p x -k modules -w /sbin/rmmod -p x -k modules -w /sbin/modprobe -p x -k modules -a always,exit -F arch=b64 -S init_module -S delete_module -k modules -e 2 """ bashrc = exec_shell([ 'echo "{}" > /etc/audit/audit.rules'.format(audit_rules) ])
import pytest from find_kedro import find_kedro from util import File, make_files_and_cd content = [ ( 2, ["nodes*"], [ File( "nodes/nodes.py", """\ from kedro.pipeline import node node_a_b = node(lambda x: x, "a", "b", name="a_b") node_b_c = node(lambda x: x, "b", "c", name="b_c") """, ) ], ), ( 2, "nodes*", [ File( "nodes/nodes.py", """\ from kedro.pipeline import node
import os from util import File testpath = r"D:\work\色情暴恐广告监测测试数据" fileUtil=File.ReadFile() fileList=fileUtil.renameFile(testpath)