Compare commits
1 Commits
677b2cccec
...
1.2.3
| Author | SHA1 | Date | |
|---|---|---|---|
| e41bd6bee7 |
@@ -6,147 +6,31 @@ local native = apis.peripheral
|
||||
local peripheral = {}
|
||||
local sides = {"top", "bottom", "left", "right", "front", "back"}
|
||||
|
||||
function peripheral.getType(name)
|
||||
if native.isPresent(name) then return native.getType(name) end
|
||||
for n = 1, #sides do
|
||||
local side = sides[n]
|
||||
if native.hasType(side, "peripheral_hub") and
|
||||
native.call(side, "isPresentRemote", name) then
|
||||
return native.call(side, "getTypeRemote", name)
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
function peripheral.getNames()
|
||||
local results = {}
|
||||
local names = {}
|
||||
for n = 1, #sides do
|
||||
local side = sides[n]
|
||||
if native.isPresent(side) then
|
||||
table.insert(results, side)
|
||||
if native.hasType(side, "peripheral_hub") then
|
||||
local remote = native.call(side, "getNamesRemote")
|
||||
for _, name in ipairs(remote) do
|
||||
table.insert(results, name)
|
||||
end
|
||||
if native.isPresent(side) then table.insert(names, side) end
|
||||
if native.hasType(side, "peripheral_hub") then
|
||||
local hubSides = native.call(side, "getConnectedSides")
|
||||
for _, hubSide in ipairs(hubSides) do
|
||||
table.insert(names, hubSide)
|
||||
end
|
||||
end
|
||||
end
|
||||
return results
|
||||
end
|
||||
|
||||
function peripheral.isPresent(name)
|
||||
if native.isPresent(name) then
|
||||
return true
|
||||
end
|
||||
|
||||
for n = 1, #sides do
|
||||
local side = sides[n]
|
||||
if native.hasType(side, "peripheral_hub") and native.call(side, "isPresentRemote", name) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function peripheral.getType(peripheral)
|
||||
if type(peripheral) == "string" then
|
||||
if native.isPresent(peripheral) then
|
||||
return native.getType(peripheral)
|
||||
end
|
||||
for n = 1, #sides do
|
||||
local side = sides[n]
|
||||
if native.hasType(side, "peripheral_hub") and native.call(side, "isPresentRemote", peripheral) then
|
||||
return native.call(side, "getTypeRemote", peripheral)
|
||||
end
|
||||
end
|
||||
return nil
|
||||
else
|
||||
local mt = getmetatable(peripheral)
|
||||
if not mt or mt.__name ~= "peripheral" or type(mt.types) ~= "table" then
|
||||
error("bad argument #1 (table is not a peripheral)", 2)
|
||||
end
|
||||
return table.unpack(mt.types)
|
||||
end
|
||||
end
|
||||
|
||||
function peripheral.hasType(peripheral, peripheral_type)
|
||||
if type(peripheral) == "string" then
|
||||
if native.isPresent(peripheral) then
|
||||
return native.hasType(peripheral, peripheral_type)
|
||||
end
|
||||
for n = 1, #sides do
|
||||
local side = sides[n]
|
||||
if native.hasType(side, "peripheral_hub") and native.call(side, "isPresentRemote", peripheral) then
|
||||
return native.call(side, "hasTypeRemote", peripheral, peripheral_type)
|
||||
end
|
||||
end
|
||||
return nil
|
||||
else
|
||||
local mt = getmetatable(peripheral)
|
||||
if not mt or mt.__name ~= "peripheral" or type(mt.types) ~= "table" then
|
||||
error("bad argument #1 (table is not a peripheral)", 2)
|
||||
end
|
||||
return mt.types[peripheral_type] ~= nil
|
||||
end
|
||||
end
|
||||
|
||||
function peripheral.getMethods(name)
|
||||
if native.isPresent(name) then
|
||||
return native.getMethods(name)
|
||||
end
|
||||
for n = 1, #sides do
|
||||
local side = sides[n]
|
||||
if native.hasType(side, "peripheral_hub") and native.call(side, "isPresentRemote", name) then
|
||||
return native.call(side, "getMethodsRemote", name)
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
function peripheral.getName(peripheral)
|
||||
local mt = getmetatable(peripheral)
|
||||
if not mt or mt.__name ~= "peripheral" or type(mt.name) ~= "string" then
|
||||
error("bad argument #1 (table is not a peripheral)", 2)
|
||||
end
|
||||
return mt.name
|
||||
end
|
||||
|
||||
function peripheral.call(name, method, ...)
|
||||
if native.isPresent(name) then
|
||||
return native.call(name, method, ...)
|
||||
end
|
||||
|
||||
for n = 1, #sides do
|
||||
local side = sides[n]
|
||||
if native.hasType(side, "peripheral_hub") and native.call(side, "isPresentRemote", name) then
|
||||
return native.call(side, "callRemote", name, method, ...)
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
function peripheral.wrap(name)
|
||||
local methods = peripheral.getMethods(name)
|
||||
if not methods then
|
||||
return nil
|
||||
end
|
||||
|
||||
local types = { peripheral.getType(name) }
|
||||
for i = 1, #types do types[types[i]] = true end
|
||||
local result = setmetatable({}, {
|
||||
__name = "peripheral",
|
||||
name = name,
|
||||
type = types[1],
|
||||
types = types,
|
||||
})
|
||||
for _, method in ipairs(methods) do
|
||||
result[method] = function(...)
|
||||
return peripheral.call(name, method, ...)
|
||||
end
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
function peripheral.find(ty, filter)
|
||||
local results = {}
|
||||
for _, name in ipairs(peripheral.getNames()) do
|
||||
if peripheral.hasType(name, ty) then
|
||||
local wrapped = peripheral.wrap(name)
|
||||
if filter == nil or filter(name, wrapped) then
|
||||
table.insert(results, wrapped)
|
||||
end
|
||||
end
|
||||
end
|
||||
return table.unpack(results)
|
||||
return names
|
||||
end
|
||||
|
||||
local disks = {}
|
||||
@@ -246,9 +130,14 @@ local function refresh()
|
||||
if not peripheral.getType(id) then disks[id] = nil end
|
||||
end
|
||||
|
||||
for _, disk in ipairs({peripheral.find("drive")}) do
|
||||
if disk.isDiskPresent() then
|
||||
disks[tostring(disk.getDiskID())]=createDisk("cctdisk"..tostring(disk.getDiskID()), disk.getMountPath(), false, fs)
|
||||
for _, name in ipairs(peripheral.getNames()) do
|
||||
if peripheral.getType(name) == "disk" then
|
||||
if not disks[name] then
|
||||
local mount = disk.getMountPath(name)
|
||||
if mount then
|
||||
disks[name] = createDisk(name, mount, false, disk)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
--:Minify:--
|
||||
|
||||
local kernel = ...
|
||||
local apis = kernel.apis
|
||||
local native = apis.peripheral
|
||||
@@ -0,0 +1,26 @@
|
||||
local args={...}
|
||||
local kernel=args[1]
|
||||
local driver={}
|
||||
|
||||
driver.name="CCT Term Module"
|
||||
driver.version="0.1.0"
|
||||
driver.type="gpio"
|
||||
driver.description="CCT redstone Module Kernel Module"
|
||||
driver.arch="cct"
|
||||
driver.author="HyperionOS Dev Team"
|
||||
driver.license="MIT"
|
||||
driver.api={}
|
||||
|
||||
function driver.load()
|
||||
-- will
|
||||
end
|
||||
|
||||
function driver.unload()
|
||||
-- Nothing to unload
|
||||
end
|
||||
|
||||
function driver.main()
|
||||
-- Nothing to run
|
||||
end
|
||||
|
||||
-- kernel.drivers.register(driver)
|
||||
@@ -132,17 +132,6 @@ function proxy:open(path, mode)
|
||||
if type(step[steps[#steps]]) == "function" then
|
||||
return step[steps[#steps]]("open", mode)
|
||||
end
|
||||
elseif tostring(steps[1])=="self" then
|
||||
local task=kernel.currentTask
|
||||
local step = newtaskproxy(task)
|
||||
for i=2, #steps-1 do
|
||||
local dat = step[steps[i]]
|
||||
if type(dat) ~= "table" then error("ENFILE") end
|
||||
step=dat
|
||||
end
|
||||
if type(step[steps[#steps]]) == "function" then
|
||||
return step[steps[#steps]]("open", mode)
|
||||
end
|
||||
else
|
||||
for i=1, #steps-1 do
|
||||
local dat = step[steps[i]]
|
||||
@@ -177,21 +166,6 @@ function proxy:type(path, mode)
|
||||
if type(step[steps[#steps]]) == "table" then
|
||||
return "directory"
|
||||
end
|
||||
elseif tostring(steps[1])=="self" then
|
||||
local task=kernel.currentTask
|
||||
if #steps==1 then return "directory" end
|
||||
local step = newtaskproxy(task)
|
||||
for i=2, #steps-1 do
|
||||
local dat = step[steps[i]]
|
||||
if type(dat) ~= "table" then error("ENFILE") end
|
||||
step=dat
|
||||
end
|
||||
if type(step[steps[#steps]]) == "function" then
|
||||
return step[steps[#steps]]("type", mode)
|
||||
end
|
||||
if type(step[steps[#steps]]) == "table" then
|
||||
return "directory"
|
||||
end
|
||||
else
|
||||
for i=1, #steps-1 do
|
||||
local dat = step[steps[i]]
|
||||
@@ -212,7 +186,7 @@ function proxy:list(path)
|
||||
local steps = kernel.vfs.splitPath(path)
|
||||
local step = data
|
||||
if #steps == 0 then
|
||||
return table.merge(table.keys(data),table.keys(kernel.tasks),{"self"})
|
||||
return table.merge(table.keys(data),table.keys(kernel.tasks))
|
||||
end
|
||||
if tonumber(steps[1]) then
|
||||
local task=kernel.tasks[steps[1]]
|
||||
@@ -226,18 +200,6 @@ function proxy:list(path)
|
||||
if type(step[steps[#steps]]) == "table" then
|
||||
return table.keys(step[steps[#steps]])
|
||||
end
|
||||
elseif tostring(steps[1])=="self" then
|
||||
local task=kernel.currentTask
|
||||
local step = newtaskproxy(task)
|
||||
if #steps==1 then return table.keys(step) end
|
||||
for i=2, #steps-1 do
|
||||
local dat = step[steps[i]]
|
||||
if type(dat) ~= "table" then error("ENOENT") end
|
||||
step=dat
|
||||
end
|
||||
if type(step[steps[#steps]]) == "table" then
|
||||
return table.keys(step[steps[#steps]])
|
||||
end
|
||||
else
|
||||
for i=1, #steps-1 do
|
||||
local dat = step[steps[i]]
|
||||
|
||||
@@ -236,18 +236,19 @@ local function nextUID()
|
||||
return max + 1
|
||||
end
|
||||
|
||||
function auth.login(uid, password)
|
||||
if type(uid) ~= "number" or type(password) ~= "string" then
|
||||
function auth.login(username, password)
|
||||
if type(username) ~= "string" or type(password) ~= "string" then
|
||||
return nil, "Authentication failure"
|
||||
end
|
||||
|
||||
local entry = getPasswdByUID(uid)
|
||||
local entry = getPasswdByUsername(username)
|
||||
if not entry then
|
||||
-- timing attack resistance
|
||||
hashPassword(password, "aaaaaaaaaaaaaaaa")
|
||||
return nil, "Authentication failure"
|
||||
end
|
||||
|
||||
local uid = tonumber(entry[1])
|
||||
local sEntry = getShadowByUID(uid)
|
||||
if not sEntry then
|
||||
hashPassword(password, "aaaaaaaaaaaaaaaa")
|
||||
@@ -272,7 +273,7 @@ function auth.login(uid, password)
|
||||
_task.egid = tonumber(entry[2]) or uid
|
||||
end
|
||||
|
||||
kernel.log("AUTH: login uid=" .. tostring(uid) .. " (" .. getPasswdByUID(uid)[3] .. ")")
|
||||
kernel.log("AUTH: login uid=" .. tostring(uid) .. " (" .. username .. ")")
|
||||
return true
|
||||
end
|
||||
|
||||
@@ -618,4 +619,4 @@ if kernel.syscalls then
|
||||
kernel.syscalls["setshell"] = auth.setShell
|
||||
kernel.syscalls["sethomedir"] = auth.setHomedir
|
||||
kernel.syscalls["setgid"] = auth.setGID
|
||||
end
|
||||
end
|
||||
|
||||
@@ -96,8 +96,8 @@ if kernel.firstBoot then
|
||||
{"sbin", REG, 0, 0, RWX_RX_RX},
|
||||
{"tmp", REG, 0, 0, RWXRWXRWX},
|
||||
{"usr", REG, 0, 0, RWX_RX_RX},
|
||||
{"var", REG, 0, 0, RWXRWXRWX},
|
||||
{"opt", REG, 0, 0, RWX_RX_RX},
|
||||
{"var", REG, 0, 0, RWX_RX_RX},
|
||||
{"opt", REG, 0, 0, RWXRWXRWX},
|
||||
})
|
||||
|
||||
mergeMeta("/bin", {
|
||||
|
||||
@@ -130,9 +130,8 @@ local function doLogin()
|
||||
|
||||
syscall.write(1, "Password: ")
|
||||
local password = readLine("*")
|
||||
local uid = syscall.getuidbyname(username)
|
||||
|
||||
local ok, err = syscall.login(uid, password)
|
||||
|
||||
local ok, err = syscall.login(username, password)
|
||||
if ok then
|
||||
local uid = syscall.getuid()
|
||||
local pwent = syscall.getpasswd(uid)
|
||||
|
||||
@@ -9,7 +9,7 @@ local currentUid = syscall.getuid()
|
||||
|
||||
local targetUid
|
||||
if targetName then
|
||||
targetUid = syscall.getuid()
|
||||
targetUid = syscall.getuid(targetName)
|
||||
if not targetUid then
|
||||
print("passwd: user '" .. targetName .. "' does not exist")
|
||||
syscall.exit(1); return
|
||||
@@ -36,7 +36,7 @@ if currentUid ~= 0 then
|
||||
if #cur > 0 then cur=cur:sub(1,-2); syscall.write(1,"\b \b") end
|
||||
else cur=cur..ch; syscall.write(1,"*") end
|
||||
end
|
||||
local ok, err = syscall.login(targetUid, cur)
|
||||
local ok, err = syscall.elevate(targetName, cur)
|
||||
if not ok then
|
||||
sleep(1)
|
||||
print("passwd: authentication failure")
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
--:Minify:--
|
||||
local targetUser = ({ ... })[1]
|
||||
local targetUser = ({ ... })[1] or "root"
|
||||
local currentUid = syscall.getuid()
|
||||
local targetUid
|
||||
if targetUser then
|
||||
targetUid = syscall.getuidbyname(targetUser)
|
||||
else
|
||||
targetUid = 0
|
||||
end
|
||||
local targetUid = syscall.getuidbyname(targetUser)
|
||||
|
||||
if not targetUid then
|
||||
print("su: user '" .. targetUser .. "' does not exist")
|
||||
@@ -30,21 +25,20 @@ if currentUid ~= 0 then
|
||||
end
|
||||
end
|
||||
|
||||
local ok, err = syscall.login(targetUid, pw)
|
||||
local ok, err = syscall.elevate(targetUser, pw)
|
||||
if not ok then
|
||||
sleep(1)
|
||||
print("su: Authentication failure")
|
||||
syscall.exit(1)
|
||||
return
|
||||
end
|
||||
else
|
||||
syscall.setuid(targetUid)
|
||||
end
|
||||
|
||||
syscall.setuid(targetUid)
|
||||
|
||||
local pwent = syscall.getpasswd(targetUid)
|
||||
local shell = (pwent and pwent.shell) or "/bin/hysh"
|
||||
local homedir = (pwent and pwent.homedir) or "/"
|
||||
local username= (pwent and pwent.username)or "Unknown"
|
||||
|
||||
local ok_cd, err_cd = pcall(syscall.chdir, homedir)
|
||||
if not ok_cd then
|
||||
@@ -52,11 +46,11 @@ if not ok_cd then
|
||||
syscall.chdir(homedir)
|
||||
end
|
||||
syscall.setEnviron("HOME", homedir)
|
||||
syscall.setEnviron("USER", username)
|
||||
syscall.setEnviron("USER", targetUser)
|
||||
syscall.setEnviron("SHELL", shell)
|
||||
|
||||
local ok, err = pcall(syscall.exec, shell)
|
||||
if not ok then
|
||||
print("su: cannot exec shell '" .. shell .. "': " .. tostring(err))
|
||||
syscall.exit(1)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -55,7 +55,7 @@ if currentUid ~= 0 then
|
||||
end
|
||||
end
|
||||
|
||||
local ok, err = syscall.login(0, pw)
|
||||
local ok, err = syscall.elevate("root", pw)
|
||||
if not ok then
|
||||
sleep(1)
|
||||
print("sudo: Authentication failure")
|
||||
|
||||
Binary file not shown.
18
manifest.lua
18
manifest.lua
@@ -3,8 +3,6 @@
|
||||
--- @diagnostic disable: duplicate-set-field
|
||||
syscall={}
|
||||
|
||||
--- @alias userinfo {username:string,homedir:string,shell:string,uid:number,gid:number}
|
||||
|
||||
--- Sets home directory of User with corresponding uid to homedir
|
||||
--- @param uid integer
|
||||
--- @param homedir string
|
||||
@@ -166,7 +164,7 @@ syscall.setpassword=function(uid, newPassword) end
|
||||
|
||||
--- Set environment variable
|
||||
--- @param key string
|
||||
--- @param value any
|
||||
--- @param value string
|
||||
--- @return boolean
|
||||
syscall.setEnviron=function(key, value) end
|
||||
|
||||
@@ -199,7 +197,7 @@ syscall.exit=function(code) end
|
||||
|
||||
--- Get environment variable
|
||||
--- @param key string
|
||||
--- @return any
|
||||
--- @return string|nil
|
||||
syscall.getEnviron=function(key) end
|
||||
|
||||
--- Continue a stopped task
|
||||
@@ -339,7 +337,7 @@ syscall.remove=function(path) end
|
||||
--- @return string|nil
|
||||
syscall.type=function(path) end
|
||||
|
||||
--- Elevate to root with password (Disabled due to VULN)
|
||||
--- Elevate to another user with password
|
||||
--- @param targetUsername string
|
||||
--- @param password string
|
||||
--- @return boolean
|
||||
@@ -376,11 +374,11 @@ syscall.setusername=function(uid, newUsername) end
|
||||
--- @return integer
|
||||
syscall.geteuid=function() end
|
||||
|
||||
--- Login as user
|
||||
--- @param uid integer
|
||||
--- Login user
|
||||
--- @param username string
|
||||
--- @param password string
|
||||
--- @return boolean
|
||||
syscall.login=function(uid, password) end
|
||||
syscall.login=function(username, password) end
|
||||
|
||||
--- Get system hostname
|
||||
--- @return string
|
||||
@@ -516,9 +514,9 @@ syscall.access=function(path, mode) end
|
||||
--- Ignore current signal
|
||||
syscall.sigignore=function() end
|
||||
|
||||
--- Get user information
|
||||
--- Get user password hash
|
||||
--- @param uid integer
|
||||
--- @return userinfo|nil
|
||||
--- @return string|nil
|
||||
syscall.getpasswd=function(uid) end
|
||||
|
||||
--- Get OS version
|
||||
|
||||
Reference in New Issue
Block a user