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": ""  } ] }'

运行结果如下:

{
	"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 调用方法

使用结果中的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"}] }'

运行结果如下:

{
	"jsonrpc": "2.0",
	"id": 1,
	"result": [0, {
		"value": "dhcp"
	}]
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值