• uhttpd调试小结


    1. ubus jsonrpc使用

    1.1 获取session id和支持的方法

    其中用户名密码根据需要修改

    curl http://127.0.0.1/ubus -d '{ "jsonrpc": "2.0", "id": 1, "method": "call", "params": [ "00000000000000000000000000000000", "session", "login", { "username": "root", "password": ""  } ] }'
    
    • 1

    运行结果如下:

    {
    	"jsonrpc": "2.0",
    	"id": 1,
    	"result": [0, {
    		"ubus_rpc_session": "6070027992e9d1edde31486c15af68e5",
    		"timeout": 300,
    		"expires": 299,
    		"acls": {
    			"access-group": {
    				"luci-app-firewall": ["read", "write"],
    				"luci-app-opkg": ["read", "write"],
    				"luci-base": ["read", "write"],
    				"luci-base-network-status": ["read"],
    				"luci-mod-network-config": ["read", "write"],
    				"luci-mod-network-dhcp": ["read", "write"],
    				"luci-mod-network-diagnostics": ["read"],
    				"luci-mod-status-channel_analysis": ["read"],
    				"luci-mod-status-firewall": ["read", "write"],
    				"luci-mod-status-index": ["read", "write"],
    				"luci-mod-status-index-dhcp": ["read"],
    				"luci-mod-status-index-dsl": ["read"],
    				"luci-mod-status-index-wifi": ["read", "write"],
    				"luci-mod-status-logs": ["read"],
    				"luci-mod-status-processes": ["read", "write"],
    				"luci-mod-status-realtime": ["read"],
    				"luci-mod-status-routes": ["read"],
    				"luci-mod-system-config": ["read", "write"],
    				"luci-mod-system-cron": ["read", "write"],
    				"luci-mod-system-flash": ["read", "write"],
    				"luci-mod-system-init": ["read", "write"],
    				"luci-mod-system-mounts": ["read", "write"],
    				"luci-mod-system-reboot": ["write"],
    				"luci-mod-system-ssh": ["read", "write"],
    				"unauthenticated": ["read"]
    			},
    			"cgi-io": {
    				"backup": ["read"],
    				"download": ["read"],
    				"exec": ["read", "write"],
    				"upload": ["write"]
    			},
    			"file": {
    				"/": ["list"],
    				"/*": ["list"],
    				"/bin/dmesg -r": ["exec"],
    				"/bin/kill": ["exec"],
    				"/bin/ping": ["exec"],
    				"/bin/ping6": ["exec", "list"],
    				"/bin/tar -tzf /tmp/backup.tar.gz": ["exec"],
    				"/bin/traceroute": ["exec"],
    				"/bin/traceroute6": ["exec", "list"],
    				"/bin/umount": ["exec"],
    				"/dev/mtdblock[0-9]*": ["read"],
    				"/etc/crontabs/root": ["read", "write"],
    				"/etc/dropbear/authorized_keys": ["read", "write"],
    				"/etc/filesystems": ["read"],
    				"/etc/firewall.user": ["read", "write"],
    				"/etc/init.d/cron reload": ["exec"],
    				"/etc/init.d/firewall restart": ["exec"],
    				"/etc/iproute2/rt_tables": ["read"],
    				"/etc/luci-uploads/*": ["write"],
    				"/etc/opkg.conf": ["read", "write"],
    				"/etc/opkg/*.conf": ["read", "write"],
    				"/etc/rc.local": ["read", "write"],
    				"/etc/sysupgrade.conf": ["read", "write"],
    				"/lib/upgrade/platform.sh": ["list"],
    				"/proc/filesystems": ["read"],
    				"/proc/mounts": ["read"],
    				"/proc/mtd": ["read"],
    				"/proc/partitions": ["read"],
    				"/proc/sys/kernel/hostname": ["read"],
    				"/proc/sys/net/ipv6/conf/*/mtu": ["read"],
    				"/proc/sys/net/ipv6/conf/*/hop_limit": ["read"],
    				"/proc/sys/net/netfilter/nf_conntrack_count": ["read"],
    				"/proc/sys/net/netfilter/nf_conntrack_max": ["read"],
    				"/sbin/block": ["exec"],
    				"/sbin/firstboot -r -y": ["exec"],
    				"/sbin/ifdown": ["exec"],
    				"/sbin/ifup": ["exec"],
    				"/sbin/ip -[46] neigh show": ["exec"],
    				"/sbin/ip -[46] route show table all": ["exec"],
    				"/sbin/logread": ["stat"],
    				"/sbin/logread -e ^": ["exec"],
    				"/sbin/reboot": ["exec"],
    				"/sbin/sysupgrade --force -k /tmp/firmware.bin": ["exec"],
    				"/sbin/sysupgrade --force -u -k /tmp/firmware.bin": ["exec"],
    				"/sbin/sysupgrade --force -u /tmp/firmware.bin": ["exec"],
    				"/sbin/sysupgrade --force /tmp/firmware.bin": ["exec"],
    				"/sbin/sysupgrade --list-backup": ["exec"],
    				"/sbin/sysupgrade --restore-backup /tmp/backup.tar.gz": ["exec"],
    				"/sbin/sysupgrade --test /tmp/firmware.bin": ["exec"],
    				"/sbin/sysupgrade -k /tmp/firmware.bin": ["exec"],
    				"/sbin/sysupgrade -n --force /tmp/firmware.bin": ["exec"],
    				"/sbin/sysupgrade -n /tmp/firmware.bin": ["exec"],
    				"/sbin/sysupgrade -u -k /tmp/firmware.bin": ["exec"],
    				"/sbin/sysupgrade -u /tmp/firmware.bin": ["exec"],
    				"/sbin/sysupgrade /tmp/firmware.bin": ["exec"],
    				"/sbin/wifi": ["exec"],
    				"/tmp/backup.tar.gz": ["write"],
    				"/tmp/firmware.bin": ["write"],
    				"/tmp/upload.ipk": ["write"],
    				"/usr/bin/btrfsck": ["list"],
    				"/usr/bin/nslookup": ["exec"],
    				"/usr/bin/ntfsfix": ["list"],
    				"/usr/bin/ping": ["exec"],
    				"/usr/bin/ping6": ["exec", "list"],
    				"/usr/bin/traceroute": ["exec"],
    				"/usr/bin/traceroute6": ["exec", "list"],
    				"/usr/lib/lua/luci/version.lua": ["read"],
    				"/usr/lib/opkg/info/netifd.control": ["read"],
    				"/usr/libexec/luci-peeraddr": ["exec"],
    				"/usr/libexec/opkg-call install *": ["exec"],
    				"/usr/libexec/opkg-call list-available": ["exec"],
    				"/usr/libexec/opkg-call list-installed": ["exec"],
    				"/usr/libexec/opkg-call remove *": ["exec"],
    				"/usr/libexec/opkg-call update *": ["exec"],
    				"/usr/libexec/opkg-list available": ["exec"],
    				"/usr/libexec/opkg-list installed": ["exec"],
    				"/usr/sbin/e2fsck": ["list"],
    				"/usr/sbin/fsck.f2fs": ["list"],
    				"/usr/sbin/fsck.fat": ["list"],
    				"/usr/sbin/ip6tables": ["list"],
    				"/usr/sbin/ip6tables --line-numbers -w -nvxL -t *": ["exec"],
    				"/usr/sbin/ip6tables -Z": ["exec"],
    				"/usr/sbin/iptables --line-numbers -w -nvxL -t *": ["exec"],
    				"/usr/sbin/iptables -Z": ["exec"],
    				"/usr/sbin/logread": ["stat"],
    				"/usr/sbin/logread -e ^": ["exec"],
    				"/www/luci-static/resources/view/status/include": ["list"]
    			},
    			"ubus": {
    				"dsl": ["metrics"],
    				"file": ["read", "write", "list", "remove", "exec", "stat"],
    				"hostapd.*": ["del_client", "wps_start", "wps_cancel", "wps_status"],
    				"iwinfo": ["assoclist", "countrylist", "freqlist", "txpowerlist", "scan", "info"],
    				"luci": ["getConntrackHelpers", "getMountPoints", "getFeatures", "getSwconfigFeatures", "getSwconfigPortState", "getConntrackList", "getRealtimeStats", "getProcessList", "getInitList", "getLEDs", "getTimezones", "getUSBDevices", "setInitAction", "setLocaltime", "setPassword", "getBlockDevices", "setBlockDetect"],
    				"luci-rpc": ["getBoardJSON", "getHostHints", "getNetworkDevices", "getWirelessDevices", "getDHCPLeases", "getDUIDHints"],
    				"network": ["get_proto_handlers"],
    				"network.interface": ["dump"],
    				"network.rrdns": ["lookup"],
    				"session": ["access", "login"],
    				"system": ["board", "info", "validate_firmware_image", "reboot"],
    				"uci": ["changes", "get", "add", "apply", "confirm", "delete", "order", "rename", "set"]
    			},
    			"uci": {
    				"dhcp": ["read", "write"],
    				"dropbear": ["read", "write"],
    				"firewall": ["read", "write"],
    				"fstab": ["read", "write"],
    				"luci": ["read", "write"],
    				"network": ["read", "write"],
    				"system": ["read", "write"],
    				"wireless": ["read", "write"]
    			}
    		},
    		"data": {
    			"username": "root"
    		}
    	}]
    }
    
    • 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
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160

    1.2 调用方法

    使用结果中的ubus_rpc_session字段和acls中ubus字段来调用,比如:

    curl http://127.0.0.1/ubus -d '{ "jsonrpc": "2.0", "id": 1, "method": "call", "params": ["6070027992e9d1edde31486c15af68e5", "uci", "get",{"config":"network","section":"wan","option":"proto"}] }'
    
    • 1

    运行结果如下:

    {
    	"jsonrpc": "2.0",
    	"id": 1,
    	"result": [0, {
    		"value": "dhcp"
    	}]
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
  • 相关阅读:
    unity中绑定动画的行为系统
    Elasticsearch:使用 Low Level Java 客户端来创建连接 - Elastic Stack 8.x
    CSS3 按钮
    代码随想录Day42 | 01背包问题| 416. 分割等和子集
    DDoS攻击频发,科普防御DDoS攻击的几大有效方法
    【深入浅出Spring6】第二期——依赖注入
    Elasticsearch索引操作(七)
    JDK动态代理在反序列化中的应用
    使用jmx exporter采集kafka指标
    Nginx的重写功能——Rewrite
  • 原文地址:https://blog.csdn.net/u010687717/article/details/126285114