Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/netgear_6220_mips32el_linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def my_bind(ql: Qiling):

def my_netgear(path, rootfs):
ql = Qiling(path, rootfs, verbose=QL_VERBOSE.DEBUG, profile="netgear_6220.ql", multithread=False)
ql.root = False
ql.os.root = False

ql.add_fs_mapper('/proc', '/proc')
ql.set_syscall(4004, my_syscall_write)
Expand Down
14 changes: 0 additions & 14 deletions qiling/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ def __init__(
self._patch_lib = []
self._debug_stop = False
self._debugger = None
self._root = False

###############################
# Properties configured later #
Expand Down Expand Up @@ -574,19 +573,6 @@ def debugger(self) -> Union[str, bool]:
def debugger(self, dbger):
self._debugger = dbger

@property
def root(self) -> bool:
""" Whether run current program as root?

Type: bool
Examples: ql.root = True
"""
return self._root

@root.setter
def root(self, root):
self._root = root

@property
def filter(self) -> str:
""" Filter logs with regex.
Expand Down
4 changes: 2 additions & 2 deletions qiling/loader/elf.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,9 @@ def __push_str(top: int, s: str) -> int:
(AUX.AT_FLAGS, 0),
(AUX.AT_ENTRY, elf_entry),
(AUX.AT_UID, self.ql.os.uid),
(AUX.AT_EUID, self.ql.os.uid),
(AUX.AT_EUID, self.ql.os.euid),
(AUX.AT_GID, self.ql.os.gid),
(AUX.AT_EGID, self.ql.os.gid),
(AUX.AT_EGID, self.ql.os.egid),
(AUX.AT_HWCAP, elf_hwcap),
(AUX.AT_CLKTCK, 100),
(AUX.AT_RANDOM, randstraddr),
Expand Down
13 changes: 13 additions & 0 deletions qiling/os/os.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,19 @@ def stdout(self, stream: TextIO) -> None:
def stderr(self, stream: TextIO) -> None:
self._stderr = stream

@property
def root(self) -> bool:
"""An indication whether the process is running as root.
"""

# for this to work the os derivative should override this property
# and implement the os logic. in case it is not, return False
return False
Copy link
Member

@wtdcode wtdcode Oct 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have something equivalent on Windows?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how Windows manages that, neither what would be the indicator.
For now the only use case we have is Linux, so it doesn't break anything.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you know what. maybe sudo is better compare to root.


@root.setter
def root(self, enabled: bool) -> None:
raise NotImplementedError('Running as root is not implemented for this OS')

def resolve_fcall_params(self, params: Mapping[str, Any]) -> Mapping[str, Any]:
"""Transform function call raw parameters values into meaningful ones, according to
their assigned type.
Expand Down
17 changes: 11 additions & 6 deletions qiling/os/posix/posix.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,8 @@ def __init__(self, ql: Qiling):
self.ql = ql
self.sigaction_act = [0] * 256

if self.ql.root:
self.uid = 0
self.gid = 0
else:
self.uid = self.profile.getint("KERNEL","uid")
self.gid = self.profile.getint("KERNEL","gid")
self.uid = self.euid = self.profile.getint("KERNEL","uid")
self.gid = self.egid = self.profile.getint("KERNEL","gid")

self.pid = self.profile.getint("KERNEL", "pid")
self.ipv6 = self.profile.getboolean("NETWORK", "ipv6")
Expand Down Expand Up @@ -125,6 +121,15 @@ def stderr(self, stream: TextIO) -> None:
self._stderr = stream
self._fd[2] = stream

@QlOs.root.getter
def root(self) -> bool:
return (self.euid == 0) and (self.egid == 0)

@QlOs.root.setter
def root(self, enabled: bool) -> None:
self.euid = 0 if enabled else self.uid
self.egid = 0 if enabled else self.gid

@property
def syscall(self):
return self.get_syscall()
Expand Down
2 changes: 1 addition & 1 deletion qiling/os/posix/syscall/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def ql_syscall_bind(ql: Qiling, bind_fd, bind_addr, bind_addrlen):
port, host = struct.unpack(">HI", data[2:8])
host = ql_bin_to_ip(host)

if ql.root == False and port <= 1024:
if not ql.os.root and port <= 1024:
port = port + 8000

if sin_family == 1:
Expand Down
8 changes: 4 additions & 4 deletions qiling/os/posix/syscall/unistd.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def ql_syscall_issetugid(ql: Qiling):


def ql_syscall_getuid(ql: Qiling):
return 0
return ql.os.uid


def ql_syscall_getuid32(ql: Qiling):
Expand All @@ -75,15 +75,15 @@ def ql_syscall_getgid32(ql: Qiling):


def ql_syscall_geteuid(ql: Qiling):
return 0
return ql.os.euid


def ql_syscall_getegid(ql: Qiling):
return 0
return ql.os.egid


def ql_syscall_getgid(ql: Qiling):
return 0
return ql.os.gid


def ql_syscall_setgroups(ql: Qiling, gidsetsize: int, grouplist: int):
Expand Down